Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: BrienKing on October 05, 2015, 01:22:30 AM

Title: Possible Bug: Starts Selected does not appear to focus the control.
Post by: BrienKing on October 05, 2015, 01:22:30 AM
Inside a panel, I have two input boxes and two buttons.  On all the controls I added the "UI Key Navigation" script.  I want the Username control to have focus when the game starts, so I set the "Starts Selected" option on the UIKeyNavigation script that is part of the Username TextBox.

However, when the game starts, it does not have focus.

Changing the code in UIKeyNavigation.cs from this:

  1.         void Start ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 mStarted = true;
  7.                 if (startsSelected && isColliderEnabled)
  8.                 UICamera.hoveredObject = gameObject;
  9.         }
  10.  
  11.  

To this:

  1.         void Start ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 mStarted = true;
  7.                 //if (startsSelected && isColliderEnabled)
  8.                 if (startsSelected)
  9.                 {
  10.                         UICamera.hoveredObject = gameObject;
  11.                         UIInput inp = gameObject.GetComponent<UIInput>();
  12.                         if (inp != null)
  13.                                 inp.isSelected = true;
  14.                 }
  15.         }
  16.  
  17.  

Fixes my issue.  Not sure why you are checking if the collider is enabled, so my solution may have an unforeseen side effect.
Title: Re: Possible Bug: Starts Selected does not appear to focus the control.
Post by: ArenMook on October 07, 2015, 07:51:12 PM
Highlighting will only work if your control scheme is set to Controller. So unless you explicitly unchecked everything but Controller on the UICamera, it will default to mouse control when you hit the Play button.

That modification should not be necessary, and the collider check is necessary. You basically made it possible to select objects that have no colliders -- objects that should not be interactable.