Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Seith on January 30, 2014, 09:10:49 AM

Title: Same user input to show and hide a panel?
Post by: Seith on January 30, 2014, 09:10:49 AM
Hello, I have a very basic question: Pressing the "B" button on the gamepad activates a panel in which lies a UIButton. But this UIButton's action is to close the panel when it is clicked. So when I press "B" on the gamepad the panel shows up (just the alpha toggling to 1) but as soon as I release the button the panel of course hides itself (alpha back to 0) because the UIButton does its job.

It's a typical case of the snake eating its own tail. What would be the proper way to achieve this simple behavior (same user input to show and hide a panel)? Thanks...
Title: Re: Same user input to show and hide a panel?
Post by: ArenMook on January 30, 2014, 11:24:46 AM
Do you select the button? It shouldn't get input unless it's selected. You can always delay an operation until the end of frame by using a coroutine.
Title: Re: Same user input to show and hide a panel?
Post by: Seith on January 30, 2014, 12:48:55 PM
The thing is the button (being the only button) is selected by default it seems.

So what I did is disabling the UIButton component by default. Then I added an Update function to track when the interaction button is NOT pressed and if the alpha of the panel is 1 (meaning the panel is visible) then I enable the UIButton component. That way the button does not register a press as soon as the panel is visible.

If the panel itself were properly disabled to begin with, and then enabled would the UIButton also catch the button pressing right away? Maybe I should try that...