Author Topic: UIButton "Starts Selected" problem  (Read 4005 times)

sduensin

  • Guest
UIButton "Starts Selected" problem
« on: July 07, 2013, 08:22:06 PM »
I've created a simple pause menu that consists of panel, a label, and two buttons.  The only options the user gets are to "Exit" or "Resume" the game.  I'm using a controller and would like the "Resume" button to be highlighted by default when the menu displays.  I've attached UIButtonKeys to both buttons and checked "Starts Selected" on the "Resume" button. 

When the game runs, in the Start() method I use NGUITools.SetActive(objectPauseMenu, false); to hide the menu when the game begins.  I call it again with "true" when the user requests the menu.

The problem is, the first time the menu is displayed no buttons are highlighted.  If I close the menu and show it again, things work as expected.  I've searched the forums, read the code, and tried all kinds of things.  I cannot for the life of me make that button highlight properly the first time the menu is displayed!  I'm using the full version of NGUI 2.6.3 and Unity3D 4.1.2f1.

Help!  Thanks.  :-)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton "Starts Selected" problem
« Reply #1 on: July 07, 2013, 11:32:58 PM »
I vaguely remember there being a topic on this about two or three weeks ago. I think the consensus was to have the following UIButton.OnEnable function:
  1.         /// <summary>
  2.         /// If the collider is disabled, assume the disabled color.
  3.         /// </summary>
  4.  
  5.         protected override void OnEnable ()
  6.         {
  7.                 if (isEnabled) base.OnEnable();
  8.                 else UpdateColor(false, true);
  9.         }

sduensin

  • Guest
Re: UIButton "Starts Selected" problem
« Reply #2 on: July 08, 2013, 02:18:02 PM »
Thank you for the quick response.  I looked inside my UIButton.cs and it already has that code.  :-/

sduensin

  • Guest
Re: UIButton "Starts Selected" problem
« Reply #3 on: July 08, 2013, 10:10:29 PM »
I fixed it.  I cheated.  I no longer have any "Start Selected" button.  I wrote a script that sets UICamera.selectedObject to the button I want 0.1 seconds after the GUI is displayed.  I attached that script to the root GameObject of my UI.

greay

  • Guest
Re: UIButton "Starts Selected" problem
« Reply #4 on: December 12, 2013, 07:28:43 PM »
I'm *still* seeing this problem in the latest version. Is ignoring "starts selected" and manually selecting the button after a delay the only solution?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton "Starts Selected" problem
« Reply #5 on: December 13, 2013, 05:34:31 AM »
What's the issue exactly? The controller example that comes with NGUI behaves as expected in regards to highlighting.

mookanana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIButton "Starts Selected" problem
« Reply #6 on: July 03, 2014, 09:25:18 PM »
sorry for resurrecting this old thread, but I wanted to share that I just had this issue and fixed it at least for my code. The issue came because I was changing the enabled state in one of my start() buttons to disabled, to ensure that users don't click on anything as the buttons are fading in for that split second.