Author Topic: UIButtonKeys panel switching  (Read 2251 times)

Memige

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
UIButtonKeys panel switching
« on: March 14, 2014, 01:12:21 PM »
Hey there,

Quick question on the intended workflow.
Our project is using gamepads only for input, and so we are using UIButtonkeys on most everything menu related.  The current flow that we have is the following:
UIButtonkey on a menu button is given an Select On value of the button on the next menu, the UIButton is given on click functions to activate the next panel through NGUITools, fire any callback we may want at the time, and lastly to deactivate the current panel, again through NGUITools.  Previously this worked without a problem, as the UIButtonKeys script merely checked to see if the target button was not null; however, in the latest version it now checks to see if it is Active.  As the button is on a panel that is being activated, but in race conditions often isn't yet, the selection fails and I end up with no object in focus.  As a temporary work around I can alter UIButtonKeys to not care if the target is active yet, but I'm assuming there was a good reason for changing it, and I'd rather adjust my flow to fit the intended use, than to screw with the plug-in to make it fit my flow.

So given an active panel with a focused button, what is the intended method of deactivating the current menu, activating a new one, and setting the current focused object to a specific button on the newly activated menu?

Running NGUI 3.5.4 pro on Unity 4.3.4f1 Pro

Thanks Much,
Memige Den Adel
LOOT Entertainment

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonKeys panel switching
« Reply #1 on: March 14, 2014, 01:27:12 PM »
You should do the enabling/disabling first, before UIButtonKeys does its thing. In the Controller Input example I do this by ensuring that the UIButtonKeys script is last in inspector -- after UIPlayAnimation scripts which perform the enabling and disabling of objects.

The "is active" check is there so that the selection is never lost when using the controller so you are never stuck in a situation where some disabled object has the selection, breaking your controller-based navigation.

Memige

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIButtonKeys panel switching
« Reply #2 on: March 14, 2014, 06:21:44 PM »
Thanks for the quick reply.

I don't seem to be getting the behavior you describe.  My layout is as you describe, with UIButtonKeys being the last components in the inspector, and the enable/disable happening from a callback set in UIButton's OnClick list.  After comparing what I have to the Controller Example scene, I believe the difference is I am not doing animations between menus, just a simple disable/enable.  This means that there is very little time in my flow during which both panels are active (Likely only a frame, depending on how NGUITools handles that)  Subsequently, the check in UIButtonKeys (Which checks to see if both the current and destination objects are active simultaneously) is very rarely if ever going to pass.  In the Controller example, the bring in and take out animations cause an approximately 0.5 second window in which both panels are active, giving plenty of time for UIButtonKeys to pass the baton, so to speak.  Our artists were pretty adamant that we not to transition animations, but if it's going to cause tech issues, I can convince them to do something simple.  Is there any way to get this to work without transition anims?

Best Regards,
Memige

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonKeys panel switching
« Reply #3 on: March 14, 2014, 08:38:00 PM »
As a rule of thumb, if using existing components doesn't quite cut it, just write a simple script yourself. Instead of just enabling/disabling something, have a script that enables/disables as well as changes the selection.

Memige

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIButtonKeys panel switching
« Reply #4 on: March 16, 2014, 01:52:29 PM »
Alright, after playing around with a few options here is what I came up with:  I have a simple script as you suggested, which handles switching panels and passing selection between them, now I just call my scripts Bring-In and Take-Out functions as button events, and use the UIButton.current static combined with a button keys component look-up to quickly grab the next button I should select.  By caching the previous panel and button, this also makes canceling out of a menu a breeze. 

Having another minor issue that I'll post a new topic on, but thank you for your help on getting this part resolved.
-Memige