2D Toolkit Forum
2D Toolkit => Support => Topic started by: calclavia on November 06, 2013, 02:46:50 pm
-
Hi,
I'd like to ask if there is a function I can call on the UILayoutContainerSizer to make it reset all the UI elements inside of it to have fixed size during runtime (similar to the button pressed in the editor)?
I have a level selection menu with buttons being added in real-time based on how many levels are loaded. I need them to be able to layout-evenly row by row. It's a very typical level selection menu:
(http://puu.sh/5aohb.jpg)
Any help is appreciated.
Thanks,
Calclavia
-
The scrollable area sample (#5) shows a demo of adding fixed size objects to layout container sizer. I think that should do what you need.
-
Thanks! That worked! Is there a way I can make it automatically create new lines? I want to have 3 columns (each with about 5-6 buttons for different levels) or do I have to do that manually by creating 3 layout containers?
Example of one column:
(http://puu.sh/5bijl.jpg)
Also, is there a way to add an event so when someone clicks on the button, it will call a function with a specific parameter based on the id of that button?
Something like:
onClick += loadLevel(levelID);
Many thanks!
-
You can't do multiline automatically. If you want that functionality, it might be easier to just write a new LayoutContainerSizer that does this. The code that handles this is pretty straightforward - tk2dUILayoutContainerSizer.DoChildLayout is where everything happens. It'll be a lot easier if you only care about fixed size items.
-
Thanks, I'll work around that then.
You might have missed my second question:
Is there a way to add an event so when someone clicks on the button, it will call a function with a specific parameter based on the id of that button?
Something like:
onClick += loadLevel(levelID);
Right now I can add an event for a function without parameter. Is there a way to do it for functions with parameters?
-
use OnClickUIItem - that will pass a reference to your object to the callback, you can map that to levelIds or something somehow.