Author Topic: "Select on tab" not functioning correctly when GameObject is deactivated  (Read 3633 times)

Screenhog

  • Guest
I have a set of UIInput objects that I'm using to create a form, and a gameObject parent. I'm using "Select on Tab" to enable people to use the Tab key to go from one UIInput to the next.

If the GameObject parent stays active, then everything works fine. However, if I deactivate the parent GameObject (even using NGUITools.SetActive) and then reactivate the parent, "Select on Tab" doesn't work properly. Instead of tabbing from one UIInput to the next, it tabs to the last UIInput in the form.

Any ideas on how to fix this (other than adding the form as a prefab, which I'll do if there's no other option)?

Also, could there be an option to add Shift+Tab to go back up a form?

Screenhog

  • Guest
So... did I actually encounter a bug? Am I doing something wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Line 347 of UIInput:
  1.                         if (selectOnTab != null && Input.GetKeyDown(KeyCode.Tab))
  2.                         {
  3.                                 UICamera.selectedObject = selectOnTab;
  4.                         }
My guess is that what happens is this: Input A's Update gets the event, selects the next one. The next one's update happens, goes through the same logic, and since it's now selected -- processes the tab as well. So you basically get a chain of tab events from a single press. I'll see if I can come up with an elegant way of fixing this.

ankit khetrapal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
SELECT ON TAB PROBLEM SOLVED

i have attached a new modified UIInput.cs file which fixes the select on tab bug...

Following modifications are there in the script-

1.) Declared a new private bool variable "isOnTab" - 

private bool isOnTab = false;

2.) Make isOnTab = false at the start of OnSelect() function

3.) Write the following code just after Update() function and before the "if(selected)" code part -

      if (selectOnTab && Input.GetKeyDown(KeyCode.Tab))
        {
            isOnTab = true;
        }

4.) In the code -

        if (selected)
        {
   if (selectOnTab != null && Input.GetKeyDown(KeyCode.Tab))
        {
   UICamera.selectedObject = selectOnTab;
   }


        CHANGE - Input.GetKeyDown to Input.GetKeyUp  and add "&& isOnTab"

       the code changes to


        if (selected)
        {
        if (selectOnTab != null && Input.GetKeyUp(KeyCode.Tab) && isOnTab)
       {
   UICamera.selectedObject = selectOnTab;
       }


The idea here is to select a new gameObject only if the TAB key is released (not pressed) and also to ensure that the Update() function of the next gameObject does not consider TAB key released even if it is not pressed down.
« Last Edit: July 19, 2013, 05:52:23 AM by ankit khetrapal »