Ejemplo n.º 1
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab) && system.currentSelectedGameObject != null)
        {
            bool       isShiftPressed = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
            Selectable current        = system.currentSelectedGameObject.GetComponent <Selectable>();
            Selectable next           = (isShiftPressed ? current.FindSelectableOnUp() : current.FindSelectableOnDown());
            InputField nextAsInput    = next as InputField;

            // next is null - return back as far as you can
            if (nextAsInput == null)
            {
                Selectable prev        = (isShiftPressed ? current.FindSelectableOnDown() : current.FindSelectableOnUp());
                InputField prevAsInput = prev as InputField;
                if (prevAsInput == null)
                {
                    // both next AND prev are not input fields - do nothing
                    return;
                }

                while (prevAsInput != null)
                {
                    current     = prev;
                    prev        = (isShiftPressed ? current.FindSelectableOnDown() : current.FindSelectableOnUp());
                    prevAsInput = prev as InputField;
                }
                next        = current;
                nextAsInput = current as InputField;
            }
            Debug.Log("Selecting next: " + nextAsInput.ToString());
            next.Select();
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (myEventSystem.currentSelectedGameObject == null)
        {
            return;
        }

        currentObject = myEventSystem.currentSelectedGameObject.GetComponent <Selectable> ();

        if (InputManager.SelectButtonDown())
        {
            if (currentObject.GetComponent <Button> () == null)
            {
                return;
            }
            Button button = currentObject.GetComponent <Button> ();
            ExecuteEvents.Execute(button.gameObject, new BaseEventData(myEventSystem), ExecuteEvents.submitHandler);
        }

        if (InputManager.UpButtonDown())
        {
            if (currentObject.FindSelectableOnUp() == null)
            {
                return;
            }
            GameObject nextObj = currentObject.FindSelectableOnUp().gameObject;
            myEventSystem.SetSelectedGameObject(nextObj);
            Debug.Log("Navigate up");
        }
        if (InputManager.DownButtonDown())
        {
            if (currentObject.FindSelectableOnDown() == null)
            {
                return;
            }
            GameObject nextObj = currentObject.GetComponent <Selectable> ().FindSelectableOnDown().gameObject;
            myEventSystem.SetSelectedGameObject(nextObj);
            Debug.Log("Navigate down");
        }
        if (InputManager.LeftButtonDown())
        {
            if (currentObject.FindSelectableOnLeft() == null)
            {
                return;
            }
            GameObject nextObj = currentObject.FindSelectableOnLeft().gameObject;
            myEventSystem.SetSelectedGameObject(nextObj);
            Debug.Log("Navigate left");
        }
        if (InputManager.RightButtonDown())
        {
            if (currentObject.FindSelectableOnRight() == null)
            {
                return;
            }
            GameObject nextObj = currentObject.FindSelectableOnRight().gameObject;
            myEventSystem.SetSelectedGameObject(nextObj);
            Debug.Log("Navigate right");
        }
    }
Ejemplo n.º 3
0
 private void OnDestroy()
 {
     if (EventSystem.current == null)
     {
         return;
     }
     if (EventSystem.current.currentSelectedGameObject == gameObject)
     {
         if (m_selectable.FindSelectableOnUp() != null)
         {
             m_selectable.FindSelectableOnUp().Select();
         }
         else if (m_selectable.FindSelectableOnDown() != null)
         {
             m_selectable.FindSelectableOnDown().Select();
         }
         else if (m_selectable.FindSelectableOnLeft() != null)
         {
             m_selectable.FindSelectableOnLeft().Select();
         }
         else if (m_selectable.FindSelectableOnRight() != null)
         {
             m_selectable.FindSelectableOnRight().Select();
         }
     }
 }
    Selectable Previous(Selectable current)
    {
        switch (Direction)
        {
        case DirectionEnum.UpDown:
            return(current.FindSelectableOnUp());

        case DirectionEnum.LeftRight:
            return(current.FindSelectableOnLeft());
        }
        return(current.FindSelectableOnUp());
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Shows a specific panel.
    /// </summary>
    /// <param name="panelName"> The requested panel name.</param>
    public void ShowPanel(String panelName)
    {
        currentSelected = null;
        GameObject currentPanel = transform.FindChild(panelName).gameObject;

        currentPanel.SetActive(true);
        foreach (Transform t in currentPanel.transform)
        {
            // Activate the game panel.
            t.gameObject.SetActive(true);

            // Find any selectable object.
            if (currentSelected == null)
            {
                currentSelected = t.gameObject.GetComponent <Selectable>();
            }
        }

        lowestSelectable  = currentSelected;
        highestSelectable = currentSelected;

        while (lowestSelectable.FindSelectableOnDown() != null)
        {
            lowestSelectable = lowestSelectable.FindSelectableOnDown();
        }
        while (highestSelectable.FindSelectableOnUp() != null)
        {
            highestSelectable = highestSelectable.FindSelectableOnUp();
        }

        currentSelected = highestSelectable;

        // This is necessary to refresh the selected game object if the same was already selected.
        if (eventSystem.currentSelectedGameObject == highestSelectable.gameObject)
        {
            eventSystem.SetSelectedGameObject(lowestSelectable.gameObject);
        }
        eventSystem.SetSelectedGameObject(highestSelectable.gameObject);

        // This is necessary to reopen any cute menu elements that are not option panels.
        foreach (Transform t in gameObject.transform)
        {
            if (!(t.gameObject.name.ToLower().Contains("panel")))
            {
                t.gameObject.SetActive(true);
            }
        }
    }
Ejemplo n.º 6
0
    public InventorySlotUI FindNeighbours(UIMoveDirection dir)
    {
        InventorySlotUI s = null;

        if (dir == UIMoveDirection.Down)
        {
            if (selectable.FindSelectableOnDown().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Up)
        {
            if (selectable.FindSelectableOnUp().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Right)
        {
            if (selectable.FindSelectableOnRight().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Left)
        {
            if (selectable.FindSelectableOnLeft().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        return(s);
    }
Ejemplo n.º 7
0
        private void Previous()
        {
            EventSystem eventSystem = EventSystem.current;

            Selectable currentSelectable = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();

            if (currentSelectable == null)
            {
                return;
            }

            Selectable previousSelectable = currentSelectable.FindSelectableOnLeft();

            if (previousSelectable == null)
            {
                previousSelectable = currentSelectable.FindSelectableOnUp();

                if (previousSelectable == null)
                {
                    return;
                }
            }

            InputField inputfield = previousSelectable.GetComponent <InputField>();

            if (inputfield != null)
            {
                inputfield.OnPointerClick(new PointerEventData(eventSystem));
            }

            eventSystem.SetSelectedGameObject(previousSelectable.gameObject, new BaseEventData(eventSystem));
        }
Ejemplo n.º 8
0
        void Update()
        {
            if (UIManager.Instance.InputNavigateKeyDownHandler != null && UIManager.Instance.InputNavigateKeyDownHandler.Invoke() && isSelect)
            {
                Selectable next = null;
                Selectable sec  = system.currentSelectedGameObject.GetComponent <Selectable>();

                next = sec.FindSelectableOnDown();

                if (next == null) //Recycle
                {
                    Selectable temp         = sec;
                    Selectable temp_notNull = temp;
                    while (temp != null)
                    {
                        temp_notNull = temp;
                        temp         = temp.FindSelectableOnUp();
                    }

                    next = temp_notNull;
                }

                InputField inputField = next.GetComponent <InputField>();
                if (inputField == null)
                {
                    return;
                }
                system.SetSelectedGameObject(next.gameObject, new BaseEventData(system));
            }
        }
Ejemplo n.º 9
0
    void ChangeSelectedByArrowKey()
    {
        GameObject goselected = eventsystem.currentSelectedGameObject;

        if (goselected == null)
        {
            return;
        }
        Selectable selected       = goselected.GetComponent <Selectable>();
        Selectable nextselectable = null;

        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            nextselectable = selected.FindSelectableOnDown();
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            nextselectable = selected.FindSelectableOnUp();
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            nextselectable = selected.FindSelectableOnRight();
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            nextselectable = selected.FindSelectableOnLeft();
        }

        if (nextselectable)
        {
            nextselectable.Select();
        }
    }
Ejemplo n.º 10
0
    void HandleTabNavigation()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            EventSystem system  = EventSystem.current;
            GameObject  curObj  = system.currentSelectedGameObject;
            GameObject  nextObj = null;
            if (!curObj)
            {
                nextObj = system.firstSelectedGameObject;
            }
            else
            {
                Selectable curSelect  = curObj.GetComponent <Selectable>();
                Selectable nextSelect =
                    Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)
                        ? curSelect.FindSelectableOnUp()
                        : curSelect.FindSelectableOnDown();

                if (nextSelect)
                {
                    nextObj = nextSelect.gameObject;
                }
            }
            if (nextObj)
            {
                system.SetSelectedGameObject(nextObj, new BaseEventData(system));
            }
        }
    }
Ejemplo n.º 11
0
    public void CheckTabKey()
    {
        if (!Input.GetKeyDown(KeyCode.Tab) || _eventSystem == null)
        {
            return;
        }

        bool       isShiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        Selectable current     = _eventSystem.currentSelectedGameObject.GetComponent <Selectable>();
        Selectable other       = isShiftDown ? current.FindSelectableOnUp() : current.FindSelectableOnDown();

        if (other == null)
        {
            return;
        }

        InputField inputfield = other.GetComponent <InputField>();

        //if it's an input field, also set the text caret
        if (inputfield != null)
        {
            inputfield.OnPointerClick(new PointerEventData(_eventSystem));
        }

        FocusOnInput(other);
    }
Ejemplo n.º 12
0
    public void FocusPrevious()
    {
        EventSystem system;

        system = EventSystem.current;

        if (!focus)
        {
            return;
        }

        Selectable current = focus.GetComponent <Selectable>();
        Selectable next    = current.FindSelectableOnLeft();

        if (!next)
        {
            next = current.FindSelectableOnUp();
        }
        if (!next)
        {
            return;
        }
        InputField inputfield = next.GetComponent <InputField>();

        if (inputfield != null)
        {
            inputfield.OnPointerClick(new PointerEventData(system));
            focus = inputfield;
        }
        system.SetSelectedGameObject(next.gameObject);
    }
Ejemplo n.º 13
0
    private void UpdateSelectable(EPlayer player, float horizontalAxis, float verticalAxis)
    {
        EventSystem currentEventSystem = EventSystem.current;

        if (currentEventSystem != null)
        {
            GameObject selectedGO = currentEventSystem.currentSelectedGameObject;
            if (selectedGO != null)
            {
                Selectable selectableGO = selectedGO.GetComponent <Selectable>();
                if (selectableGO != null)
                {
                    if (horizontalAxis < 0f)
                    {
                        selectableGO.FindSelectableOnLeft()?.Select();
                    }
                    else if (horizontalAxis > 0f)
                    {
                        selectableGO.FindSelectableOnRight()?.Select();
                    }
                    else if (verticalAxis < 0f)
                    {
                        selectableGO.FindSelectableOnDown()?.Select();
                    }
                    else if (verticalAxis > 0f)
                    {
                        selectableGO.FindSelectableOnUp()?.Select();
                    }
                }
            }
        }
    }
Ejemplo n.º 14
0
 private void NextObjectSelect(Selectable currentObject, ref Selectable nextObject)
 {
     if (currentObject != null)
     {
         // shift 누르고 있으면 (shift + tab 이면) 뒤로
         if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
         {
             nextObject = currentObject.FindSelectableOnUp();
             if (nextObject == null)
             {
                 nextObject = currentObject.FindSelectableOnLeft();
             }
         }
         else
         {
             nextObject = currentObject.FindSelectableOnDown();
             if (nextObject == null)
             {
                 nextObject = currentObject.FindSelectableOnRight();
             }
         }
     }
     // current가 null이면 선택가능한 전체에서 1번째를 잡음
     else
     {
         if (Selectable.allSelectables.Count > 0)
         {
             nextObject = Selectable.allSelectables[0];
         }
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 更新检查输入
 /// </summary>
 void Update()
 {
     if (Input.GetButtonDown("Submit") || Input.GetKeyDown(KeyCode.Return))
     {
         OnSubmit();
     }
     if (Input.GetButtonDown("Cancel"))
     {
         OnCancel?.Invoke();
     }
     if (Input.GetButtonDown("Vertical") && Input.GetAxis("Vertical") > 0)
     {
         ForcusControl(mActiveControl?.FindSelectableOnUp());
     }
     if (Input.GetButtonDown("Vertical") && Input.GetAxis("Vertical") < 0)
     {
         ForcusControl(mActiveControl?.FindSelectableOnDown());
     }
     if (Input.GetButtonDown("Horizontal") && Input.GetAxis("Horizontal") > 0)
     {
         ForcusControl(mActiveControl?.FindSelectableOnRight());
     }
     if (Input.GetButtonDown("Horizontal") && Input.GetAxis("Horizontal") < 0)
     {
         ForcusControl(mActiveControl?.FindSelectableOnLeft());
     }
 }
Ejemplo n.º 16
0
    private GameObject GetNearestOnUp(GameObject i_Source)
    {
        if (i_Source == null)
        {
            return(null);
        }

        Selectable sourceSelectable = i_Source.GetComponent <Selectable>();

        if (sourceSelectable == null)
        {
            return(null);
        }

        Selectable selectable = sourceSelectable.FindSelectableOnUp();

        while (selectable != null && !IsAvailable(selectable.gameObject))
        {
            selectable = selectable.FindSelectableOnUp();
        }

        if (selectable == null)
        {
            return(null);
        }

        return(selectable.gameObject);
    }
    public void OnSelect(BaseEventData evData)
    {
        // Don't apply skipping unless we are not interactable.
        if (m_Selectable.interactable)
        {
            return;
        }

        // Check if the user navigated to this selectable.
        if (player1.GetAxis("Menu Horizontal") < 0 || gamePadController2.GetAxis("Menu Horizontal") < 0)
        {
            Selectable select = m_Selectable.FindSelectableOnLeft();
            if (select == null || !select.gameObject.activeInHierarchy)
            {
                select = m_Selectable.FindSelectableOnRight();
            }
            StartCoroutine(DelaySelect(select));
        }
        else if (player1.GetAxis("Menu Horizontal") > 0 || gamePadController2.GetAxis("Menu Horizontal") > 0)
        {
            Selectable select = m_Selectable.FindSelectableOnRight();
            if (select == null || !select.gameObject.activeInHierarchy)
            {
                select = m_Selectable.FindSelectableOnLeft();
            }
            StartCoroutine(DelaySelect(select));
        }

        else if (player1.GetAxis("Menu Vertical") < 0 || gamePadController2.GetAxis("Menu Vertical") < 0)
        {
            Selectable select = m_Selectable.FindSelectableOnDown();
            if (select == null || !select.gameObject.activeInHierarchy)
            {
                select = m_Selectable.FindSelectableOnUp();
            }
            StartCoroutine(DelaySelect(select));
        }
        else if (player1.GetAxis("Menu Vertical") > 0 || gamePadController2.GetAxis("Menu Vertical") > 0)
        {
            Selectable select = m_Selectable.FindSelectableOnUp();
            if (select == null || !select.gameObject.activeInHierarchy)
            {
                select = m_Selectable.FindSelectableOnDown();
            }
            StartCoroutine(DelaySelect(select));
        }
    }
Ejemplo n.º 18
0
        public void FindSelectableOnUp_ReturnsNextSelectableAboveTarget()
        {
            Selectable selectableUpOfBottomLeft  = bottomLeftSelectable.FindSelectableOnUp();
            Selectable selectableUpOfBottomRight = bottomRightSelectable.FindSelectableOnUp();

            Assert.AreEqual(topLeftSelectable, selectableUpOfBottomLeft, "Wrong selectable to Up of bottom Left Selectable");
            Assert.AreEqual(topRightSelectable, selectableUpOfBottomRight, "Wrong selectable to Up of bottom Right Selectable");
        }
        private void switchSelectedUp()
        {
            Selectable next = selectable.FindSelectableOnUp();

            if (next != null)
            {
                EventSystem.current.SetSelectedGameObject(next.gameObject);
            }
        }
Ejemplo n.º 20
0
    static int FindSelectableOnUp(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        Selectable obj = LuaScriptMgr.GetUnityObject <Selectable>(L, 1);
        Selectable o   = obj.FindSelectableOnUp();

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Ejemplo n.º 21
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (EventSystem.current != null)
            {
                GameObject selected = EventSystem.current.currentSelectedGameObject;

                //try and find the first selectable if there isn't one currently selected
                //only do it if the findFirstSelectable is true
                //you may not always want this feature and thus
                //it is disabled by default
                if (selected == null && findFirstSelectable)
                {
                    Selectable found = (Selectable.allSelectables.Count > 0) ? Selectable.allSelectables[0] : null;

                    if (found != null)
                    {
                        //simple reference so that selected isn't null and will proceed
                        //past the next if statement
                        selected = found.gameObject;
                    }
                }

                if (selected != null)
                {
                    Selectable current = (Selectable)selected.GetComponent("Selectable");

                    if (current != null)
                    {
                        Selectable nextDown  = current.FindSelectableOnDown();
                        Selectable nextUp    = current.FindSelectableOnUp();
                        Selectable nextRight = current.FindSelectableOnRight();
                        Selectable nextLeft  = current.FindSelectableOnLeft();

                        if (nextDown != null)
                        {
                            nextDown.Select();
                        }
                        else if (nextRight != null)
                        {
                            nextRight.Select();
                        }
                        else if (nextUp != null)
                        {
                            nextUp.Select();
                        }
                        else if (nextLeft != null)
                        {
                            nextLeft.Select();
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 22
0
    protected override void OnSwipeUp()
    {
        base.OnSwipeUp();

        var tmp = m_currentSelectable.FindSelectableOnUp();

        m_currentSelectable = tmp ? tmp : m_currentSelectable;

        m_currentSelectable.Select();
    }
Ejemplo n.º 23
0
    // Allows quitting by pressing ESC.
    void Update()
    {
        //The following code was taken from http://answers.unity3d.com/questions/784526/46-ugui-select-next-inputfield-with-entertab.html
        //and exists solely to allow tabbing between input fields on the title screen. Whew!
        if (InputWrapper.GetKeyDown(KeyCode.Tab))
        {
            Selectable  next        = null;
            Selectable  current     = null;
            EventSystem eventSystem = EventSystem.current;

            // Figure out if we have a valid current selected gameobject
            if (eventSystem.currentSelectedGameObject != null)
            {
                // Unity doesn't seem to "deselect" an object that is made inactive
                if (eventSystem.currentSelectedGameObject.activeInHierarchy)
                {
                    current = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();
                }
            }

            if (current != null)
            {
                // When SHIFT is held along with tab, go backwards instead of forwards
                if (InputWrapper.GetKey(KeyCode.LeftShift) || InputWrapper.GetKey(KeyCode.RightShift))
                {
                    next = current.FindSelectableOnLeft();
                    if (next == null)
                    {
                        next = current.FindSelectableOnUp();
                    }
                }
                else
                {
                    next = current.FindSelectableOnRight();
                    if (next == null)
                    {
                        next = current.FindSelectableOnDown();
                    }
                }
            }
            else
            {
                // If there is no current selected gameobject, select the first one
                if (Selectable.allSelectables.Count > 0)
                {
                    next = Selectable.allSelectables[0];
                }
            }

            if (next != null)
            {
                next.Select();
            }
        }
    }
Ejemplo n.º 24
0
        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                if (EventSystem.current != null)
                {
                    GameObject selected = EventSystem.current.currentSelectedGameObject;

                    if (selected == null && findFirstSelectable)
                    {
                        Selectable found = (Selectable.allSelectables.Count > 0) ? Selectable.allSelectables[0] : null;

                        if (found != null)
                        {
                            selected = found.gameObject;
                        }
                    }

                    if (selected != null)
                    {
                        Selectable current = (Selectable)selected.GetComponent("Selectable");

                        if (current != null)
                        {
                            Selectable nextDown  = current.FindSelectableOnDown();
                            Selectable nextUp    = current.FindSelectableOnUp();
                            Selectable nextRight = current.FindSelectableOnRight();
                            Selectable nextLeft  = current.FindSelectableOnLeft();

                            if (nextDown != null)
                            {
                                nextDown.Select();
                            }
                            else if (nextRight != null)
                            {
                                nextRight.Select();
                            }
                            else if (nextUp != null)
                            {
                                nextUp.Select();
                            }
                            else if (nextLeft != null)
                            {
                                nextLeft.Select();
                            }
                        }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Return))
            {
                CallLogin();
            }
        }
Ejemplo n.º 25
0
    void Update()
    {
        //if tab has been pressed and there is no game object selected, don't do anythhing
        if (system.currentSelectedGameObject == null || !Input.GetKeyDown(KeyCode.Tab))
        {
            return;
        }

        Selectable current = system.currentSelectedGameObject.GetComponent <Selectable>();

        if (current == null)
        {
            return;
        }

        //define going up input fields by pressing leftshift or rightshift
        bool       up   = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        Selectable next = up ? current.FindSelectableOnUp() : current.FindSelectableOnDown();

        //if next object is null, define next as current object
        if (next == null)
        {
            next = current;

            Selectable pnext;

            //finding next upwards or downwards object that isn't null
            if (up)
            {
                while ((pnext = next.FindSelectableOnDown()) != null)
                {
                    next = pnext;
                }
            }
            else
            {
                while ((pnext = next.FindSelectableOnUp()) != null)
                {
                    next = pnext;
                }
            }
        }

        // simulate Inputfield MouseClick
        InputField inputfield = next.GetComponent <InputField>();

        if (inputfield != null)
        {
            inputfield.OnPointerClick(new PointerEventData(system));
        }

        //select the next item in the tab order of our direction
        system.SetSelectedGameObject(next.gameObject);
    }
Ejemplo n.º 26
0
        // Update is called once per frame
        void Update()
        {
            #region Use tab to navigate beetwen fields
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                Selectable next    = null;
                Selectable current = null;

                // Figure out if we have a valid current selected gameobject
                if (eventSystem.currentSelectedGameObject != null)
                {
                    // Unity doesn't seem to "deselect" an object that is made inactive
                    if (eventSystem.currentSelectedGameObject.activeInHierarchy)
                    {
                        current = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();
                    }
                }

                if (current != null)
                {
                    // When SHIFT is held along with tab, go backwards instead of forwards
                    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                    {
                        next = current.FindSelectableOnLeft();
                        if (next == null)
                        {
                            next = current.FindSelectableOnUp();
                        }
                    }
                    else
                    {
                        next = current.FindSelectableOnRight();
                        if (next == null)
                        {
                            next = current.FindSelectableOnDown();
                        }
                    }
                }
                else
                {
                    // If there is no current selected gameobject, select the first one
                    if (Selectable.allSelectables.Count > 0)
                    {
                        next = Selectable.allSelectables[0];
                    }
                }

                if (next != null)
                {
                    next.Select();
                }
            }
            #endregion
        }
Ejemplo n.º 27
0
    private Selectable FindUp(Selectable current)
    {
        if (this.traversed.Contains(current))
        {
            return(null);
        }
        this.traversed.Add(current);
        Selectable selectable = current.FindSelectableOnUp();

        return(!this.IsValidSelectable(selectable) ? this.FindUp(selectable) : selectable);
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Selects up.
    /// </summary>
    private void SelectUp()
    {
        Selectable nextSelected;

        nextSelected = currentSelected.FindSelectableOnUp();
        if (nextSelected == null)
        {
            nextSelected = lowestSelectable;
        }
        eventSystem.SetSelectedGameObject(nextSelected.gameObject);
        currentSelected = nextSelected;
    }
Ejemplo n.º 29
0
    private void Update()
    {
        if (system.currentSelectedGameObject == null || !Input.GetKeyDown(KeyCode.Tab))
        {
            return;
        }

        Selectable current = system.currentSelectedGameObject.GetComponent <Selectable>();

        if (current == null)
        {
            return;
        }

        bool       up   = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        Selectable next = up ? current.FindSelectableOnUp() : current.FindSelectableOnDown();

        // We are at the end or the beginning, go to either, depends on the direction we are tabbing in
        // The previous version would take the logical 0 selector, which would be the highest up in your editor hierarchy
        // But not certainly the first item on your GUI, or last for that matter
        // This code tabs in the correct visual order
        if (next == null)
        {
            next = current;

            Selectable pnext;
            if (up)
            {
                while ((pnext = next.FindSelectableOnDown()) != null)
                {
                    next = pnext;
                }
            }
            else
            {
                while ((pnext = next.FindSelectableOnUp()) != null)
                {
                    next = pnext;
                }
            }
        }

        // Simulate Inputfield MouseClick
        InputField inputfield = next.GetComponent <InputField>();

        if (inputfield != null)
        {
            inputfield.OnPointerClick(new PointerEventData(system));
        }

        // Select the next item in the taborder of our direction
        system.SetSelectedGameObject(next.gameObject);
    }
Ejemplo n.º 30
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            Selectable next    = null;
            Selectable current = null;

            // current 갱신 (현재 선택되어있는 오브젝트가 active상태면 current로)
            if (eventSystem.currentSelectedGameObject != null)
            {
                if (eventSystem.currentSelectedGameObject.activeInHierarchy)
                {
                    current = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();
                }
            }

            // current가 존재하면 next를 찾음
            if (current != null)
            {
                // shift 누르고 있으면 (shift + tab 이면) 뒤로
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    next = current.FindSelectableOnUp();
                    if (next == null)
                    {
                        next = current.FindSelectableOnLeft();
                    }
                }
                else
                {
                    next = current.FindSelectableOnDown();
                    if (next == null)
                    {
                        next = current.FindSelectableOnRight();
                    }
                }
            }
            // current가 null이면 선택가능한 전체에서 1번째를 잡음
            else
            {
                if (Selectable.allSelectables.Count > 0)
                {
                    next = Selectable.allSelectables[0];
                }
            }

            // next가 존재하면 선택(포커스)
            if (next != null)
            {
                next.Select();
            }
        }
    }