Hello Guest

Author Topic: Problem with setting up UI.  (Read 6199 times)

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Problem with setting up UI.
« on: January 18, 2014, 03:26:45 pm »
Hi,

In various parts of the UI documentation, you refer to "Setting up UI" but I can't find it (like here: http://www.2dtoolkit.com/docs/latest/ui/customizing_button.html). I could put a BasicButton on the scene but don't know how to attach the behavior from the documentation to it.

I really wish there was a complete tutorial for UI as I see there are some advance stuff there but can't get my head around them.

Thanks.
« Last Edit: January 18, 2014, 03:33:42 pm by test84 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with setting up UI.
« Reply #1 on: January 19, 2014, 02:13:51 pm »
What do you mean by "don't know how to attach the behavior from the documentation to it." Which step is that?

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Problem with setting up UI.
« Reply #2 on: January 19, 2014, 04:31:56 pm »
Hi,

In the documentation page I posted, http://www.2dtoolkit.com/docs/latest/ui/customizing_button.html, the first number is to: "Follow instructions in 'Setting up UI' tutorial." and I can't find it anywhere.

2- Also in this fie: http://www.2dtoolkit.com/docs/latest/ui/system.html it says that to listen to events I should use this code:

Code: [Select]
void OnEnable()
{
    uiItem.OnDown += ButtonDown;
    uiItem.OnClickUIItem += Clicked;
}

void ButtonDown()
{
    Debug.Log("Button Down");
}

void Clicked(tk2dUIItem clickedUIItem)
{
    Debug.Log("Clicked:" + clickedUIItem);
}

//Also remember if you are adding event listeners to events you need to also remove them:
void OnDisable()
{
    uiItem.OnDown -= ButtonDown;
    uiItem.OnClickUIItem -= Clicked;
}

But first of all, what is uiItem? Should I make an empty C# script, put this code inside it and attach it to my button?

Wish there was a simple tutorial on how to make these from ground up. I tried to understand it via demo scenes but had no luck.

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with setting up UI.
« Reply #3 on: January 20, 2014, 12:38:59 pm »
1. That is a remnant from an old tutorial. That step is no longer required. I've updated that now.

2. All interactive elements in tk2d UI have a tk2dUIItem component attached to them. The example shows shows how you'd subscribe to and unsubscribe form the event - there are many ways to get the reference to the object in Unity. The most common is to create a public variable and dragging a reference to it. Thats how all the demos work. You would probably put it into your ui controller script to handle all the rest of the UI.

Out of curiosity what would you expect in the tutorial? The tutorials right now target those that know how things work in Unity and only show things that are specific to tk2d. We could go much more in depth of course, but that would reduce the amount of time we'd have to work on updates / provide support / etc. The reason I ask is so I can further optimise the balance, depending on our users needs.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Problem with setting up UI.
« Reply #4 on: January 20, 2014, 05:08:06 pm »
1. That is a remnant from an old tutorial. That step is no longer required. I've updated that now.

Noted, thanks!

2. All interactive elements in tk2d UI have a tk2dUIItem component attached to them. The example shows shows how you'd subscribe to and unsubscribe form the event - there are many ways to get the reference to the object in Unity. The most common is to create a public variable and dragging a reference to it. Thats how all the demos work. You would probably put it into your ui controller script to handle all the rest of the UI.

I'm sorry but I still do not understand how to do set up for a simple button and attach those delegates I posted before.

What is "uiItem" ? Is it "tk2dUIItem" component attached to the current button? So I have to create a C# script, attach it to the button and use GetComponent<tk2dUIItem>() on it and assing it uiItem in it's like Awake call?

Should add a tk2dUIManager as well to each scene?

Out of curiosity what would you expect in the tutorial? The tutorials right now target those that know how things work in Unity and only show things that are specific to tk2d. We could go much more in depth of course, but that would reduce the amount of time we'd have to work on updates / provide support / etc. The reason I ask is so I can further optimise the balance, depending on our users needs.

I'm well familiar with Unity. But as someone new to tk2d, I have some recommendations:

1- Make quick video tutorials rather than text based ones.

Honestly, I learned a lot by user created tutorials of tk2d rather than your whack-a-mole tutorial. I suggest you just do quick (mostly 15min) tutorials for basic stuff to get people, like me, started and from then on we can tag along since I believe you have a similar architecture for the UI components and if one learns how to work with button, I think they can easily transfer that knowledge to other components as well.

I believe you can safely assume that the audience has a basic Unity understanding and skip anything on the Unity side. OK, maybe a little on stuff like delegates and events but focus on tk2d.

I see that people, mostly my students, are interested in video tutorials rather than text based ones. But then again, some things are better be in text format so you can re-read them but it's up to you.

I personally think it's easier to do video tutorial rather than typing.

(Also you never finished the whack-a-mole tutorial! I checked it several times so far with high hopes and crossed fingers ...)

2- Other than that, I think you need some clean and simple scenes. I loved your demo scenes but could not learn much from them because from my understanding, they were created for the demo purposes and lacked the engineering that a real world game requires.

Maybe you can have two sets of demo scenes, one to show the awesome features you have and another just to show how to use the components. We use Unity and tk2d to get up and running fast, right? ;)

3- Update your tutorials when you edit something that breaks compatibility and hence renders older tutorials useless.
« Last Edit: January 20, 2014, 09:20:32 pm by test84 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with setting up UI.
« Reply #5 on: January 20, 2014, 09:22:23 pm »
Code: [Select]
I'm sorry but I still do not understand how to do set up for a simple button and attach those delegates I posted before.

What is "uiItem" ? Is it "tk2dUIItem" component attached to the current button? So I have to create a C# script, attach it to the button and use GetComponent<tk2dUIItem>() on it and assing it uiItem in it's like Awake call?

No. While you could do that, I wouldn't recommend it if you were building a GUI app as you'd litter your codebase with lots of little not particularly modular scripts. IMO, the way the demo scenes are set up are a much much better way - i.e. you would have a controller script with public tk2dUIItems, then drag & drop a reference into the slot in the inspector. We usually build one controller per "dialog box / screen", as its usually specific code anyway.

1 - video tutorials might be easier to make initially, but significantly higher cost to maintain. We change stuff frequently enough based on feedback and its considerably easier to change. Seeing that we can and do miss out bits when updating tutorials, this could end up sucking up a serious amount of resources we don't have.

The whack a mole tutorial is done, again we changed how some things work and the way some of the GUI was created is no longer the recommended way (we added UI layouts which greatly simplified UI setup). You can find the second part here - http://2dtoolkit.com/docs/latest/tutorial/whack_a_mole/extras.html

2 - I disagree with this, especially for the UI scenes. That code was more or less ripped straight out of a real world project. As is the tile map demo (it was a little internal game, from which we stripped out a lot of the game logic).

3 - Yup we already do spend a bit of time on this but I think we could do better. Will need to check harder next time - some things do slip through though. An idea is maybe to add a report error button or something similar - could help weed out errors quicker.


test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Problem with setting up UI.
« Reply #6 on: January 20, 2014, 10:58:59 pm »
Code: [Select]
No. While you could do that, I wouldn't recommend it if you were building a GUI app as you'd litter your codebase with lots of little not particularly modular scripts. IMO, the way the demo scenes are set up are a much much better way - i.e. you would have a controller script with public tk2dUIItems, then drag & drop a reference into the slot in the inspector. We usually build one controller per "dialog box / screen", as its usually specific code anyway.
[/quote]

Thanks, would you please show me a scene that you used this method so I can see it in action?

The only scene I see related to UI is 6 - button and 3d sprites and in that I don't find these new stuff and I believe it's deprecated.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with setting up UI.
« Reply #7 on: January 20, 2014, 11:04:47 pm »
TK2DROOT/tk2dUI_demo/1, 2, 3, 5. All of these use a similar pattern, there is one corresponding demo controller for each of these.