- Home /
EZGUI - Changing UIButton states from another script
Hi guys,
I am an EZGUI/SM2 newbie and am trying to port my title screen menu system to utilize these. I have a TV screen which begins by displaying a non-interactive/clickable animated texture which after a few seconds displays a different animated texture that can be clicked. After it has been clicked, it moves to a third texture which is again non-clickable. However, if it is not clicked it will move onto a different third texture. For this purpose the UIButton control with its various states seems ideal and I have managed to create the animated textures and add them to the UIButton component successfully.
The process goes like this:
If Texture_2 not clicked:
non-clickable --------------> clickable ----------------> non-clickable
Texture_1 ----------------> Texture_2 ----------------> Texture_3
If Texture_2 clicked:
non-clickable --------------> clickable ----------------> non-clickable
Texture_1 ----------------> Texture_2 ----------------> Texture_4
However, I am unsure of how to manipulate the button states in script. For example, I have set my 'Disabled' texture in the UIButton component in the Inspector, but when does this disabled time come into play? Also, as there are 2 different ways to go (if clicked or not) after Texture_2, how might I go about describing this from another script?
Any guidance on this would be great. Thanks
Answer by robertbu · Jan 14, 2013 at 05:02 AM
I've done some work with EZGUI, but I by no means an expert. What I think you want to use to implement your "button" is a State Toggle Button (UIStateToggleBtn) rather than a UIButton. It is described as, "The State Toggle Button control type works much like a traditional checkbox/toggle button, except that it supports an arbitrary number of states. It will advance incrementally from one state to the next every time it is clicked/tapped, and upon reaching the last state, if clicked/tapped again, it will return to the first state and start over."
Typically I access the class by adding my own script to the game object that has the button and then doing something like:
UIStateToggleBtn ustb = GetComponent<UIStateToggleBtn>();
The class has a SetState() method, so you might be able to just reset the state to the current one on a click if it should be disabled. But if not you can use one or more of SetInputDelegate() AddInputDelegate() SetValueChangeDelegate() and AddValueChangeDelegate() to implement your disabled state. Or you can subclass UIStateToggleBtn class and override the SetState method.