Author Topic: Dialogs and UIKeyNavigation  (Read 2830 times)

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Dialogs and UIKeyNavigation
« on: May 28, 2014, 08:11:59 AM »
I am having a little problem to find a good solution for UIKeyNavigation with overlay interface, like a dialog or popup.

It works but I am not very confortable with the solution. Any tips?

Show dialog:

  • set selected object to null
  • add/enable dialog gameobject
  • apply and wait for fade in effect
  • disable all UIKeyNavigation and UIKeyBinder that not belongs to dialog gameobject and its children (ExclusiveNavigation)

Hide dialog:

  • apply and wait fade out effect
  • disable/remove dialog gameobject
  • enable all UIKeyNavigation and UIKeyBinder (FreeNavigation)

Code for exclusive and free navigation.

   
  1. public static void ExclusiveNavigation(GameObject gameObject) {
  2.                 var navs = GameObject.FindObjectsOfType<UIKeyNavigation>();
  3.                 var binds = GameObject.FindObjectsOfType<UIKeyBinding>();
  4.                 var currentNav = gameObject.GetComponentsInChildren<UIKeyNavigation>();
  5.                 foreach (var i in navs) {
  6.                         var index = System.Array.IndexOf(currentNav, i);
  7.                         var enabled = index >= 0;
  8.                         i.enabled = enabled;
  9.                 }
  10.  
  11.                 var currentBinds = gameObject.GetComponentsInChildren<UIKeyBinding>();
  12.                 foreach (var i in binds) {
  13.                         var index = System.Array.IndexOf(currentBinds, i);
  14.                         i.enabled = index >= 0;
  15.                 }
  16.         }
  17.  
  18.         public static void FreeNavigation() {
  19.                 var navs = GameObject.FindObjectsOfType<UIKeyNavigation>();
  20.                 var binds = GameObject.FindObjectsOfType<UIKeyBinding>();
  21.                 foreach (var i in navs) i.enabled = true;
  22.                 foreach (var i in binds) i.enabled = true;
  23.         }

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Dialogs and UIKeyNavigation
« Reply #1 on: May 28, 2014, 09:13:38 AM »
Because UICamera.selectedObject is asyncrhonous, the object will be still selected when the UIKeyNavigation from dialog get active. So, I need to manually set the selected object in ExclusiveNavigation and FreeNavigation.

Its working, I only need some more eyes for better solution :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dialogs and UIKeyNavigation
« Reply #2 on: May 29, 2014, 05:51:01 AM »
Seems like a strange way of doing it. Why do any of this? The controller menu example has different menus, and I don't do any of this disabling while animating. The target button gets selected right away as the new window opens.

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Dialogs and UIKeyNavigation
« Reply #3 on: May 29, 2014, 03:15:22 PM »
1) In the example what is causing the buttons be automatic selected when change tab? The UIKeyNavigation only selected OnEnabled if UICamera.selectedObject is null.

This is the main reason of I need to manually select the first object when open or close a dialog.

2) In the example the key navigation are locked inside its page with overrides, and the default scene is disabled. In the situation of a dialog, I think that is easy enable/disable that edit each popup with navigation overrides.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dialogs and UIKeyNavigation
« Reply #4 on: May 30, 2014, 02:07:01 PM »
UIKeyBinding.onClick determines what gets selected when you click on the button.

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Dialogs and UIKeyNavigation
« Reply #5 on: May 31, 2014, 06:45:09 PM »
Oh.. got it. It is very visible in the component inspector.... sorry :P

My current implementations use a lot of dynamic instantiation, not very friendly for references. But my dirt code is encapusled, so its elegant.

Thanks