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(); } }
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 Next(Selectable current) { switch (Direction) { case DirectionEnum.UpDown: return(current.FindSelectableOnDown()); case DirectionEnum.LeftRight: return(current.FindSelectableOnRight()); } return(current.FindSelectableOnDown()); }
/// <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); } } }
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]; } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { if (system.currentSelectedGameObject == null) { return; } Selectable current = system.currentSelectedGameObject.GetComponent <Selectable> (); InputField currentInputField = current.GetComponent <InputField> (); if (currentInputField != null) { currentInputField.text = currentInputField.text.Trim(); } Selectable next = current.FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField> (); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); //if it's an input field, also set the text caret } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } else { AddRemoveOption.singleton.AddNewOption(); //OptionScript.optionList [OptionScript.optionList.Count - 1].mainInputField.OnPointerClick (new PointerEventData (system)); //system.SetSelectedGameObject (OptionScript.optionList [OptionScript.optionList.Count - 1].mainInputField.gameObject, new BaseEventData (system)); } } }
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"); } }
private void OnInputDownTabButton() { if (_currentEventSystem.currentSelectedGameObject != null) { Selectable currentSelectable = _currentEventSystem.currentSelectedGameObject.GetComponent <Selectable>(); if (currentSelectable != null) { Selectable nextSelectable = currentSelectable.FindSelectableOnDown(); if (nextSelectable != null) { InputField inputfield = nextSelectable.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick( new PointerEventData( _currentEventSystem)); // if it's an input field, also set the text caret } _currentEventSystem.SetSelectedGameObject(nextSelectable.gameObject, new BaseEventData(_currentEventSystem)); } else { #if UNITY_EDITOR Debug.Log("next nagivation element not found"); #endif } } } }
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); }
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(); } } } } }
private void Next() { EventSystem eventSystem = EventSystem.current; Selectable currentSelectable = eventSystem.currentSelectedGameObject.GetComponent <Selectable>(); if (currentSelectable == null) { return; } Selectable nextSelectable = currentSelectable.FindSelectableOnRight(); if (nextSelectable == null) { nextSelectable = currentSelectable.FindSelectableOnDown(); if (nextSelectable == null) { return; } } InputField inputfield = nextSelectable.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(eventSystem)); } eventSystem.SetSelectedGameObject(nextSelectable.gameObject, new BaseEventData(eventSystem)); }
/// <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()); } }
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)); } } }
public void FocusNext() { EventSystem system; system = EventSystem.current; if (!focus) { return; } Selectable current = focus.GetComponent <Selectable>(); Selectable next = current.FindSelectableOnRight(); if (!next) { next = current.FindSelectableOnDown(); } if (!next) { return; } InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); focus = inputfield; } system.SetSelectedGameObject(next.gameObject); }
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)); } }
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); }
private GameObject GetNearestOnDown(GameObject i_Source) { if (i_Source == null) { return(null); } Selectable sourceSelectable = i_Source.GetComponent <Selectable>(); if (sourceSelectable == null) { return(null); } Selectable selectable = sourceSelectable.FindSelectableOnDown(); while (selectable != null && !IsAvailable(selectable.gameObject)) { selectable = selectable.FindSelectableOnDown(); } if (selectable == null) { return(null); } return(selectable.gameObject); }
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(); } }
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)); } }
public void FindSelectableOnRDown_ReturnsNextSelectableBelowTarget() { Selectable selectableDownOfTopLeft = topLeftSelectable.FindSelectableOnDown(); Selectable selectableDownOfTopRight = topRightSelectable.FindSelectableOnDown(); Assert.AreEqual(bottomLeftSelectable, selectableDownOfTopLeft, "Wrong selectable to Bottom of Top Left Selectable"); Assert.AreEqual(bottomRightSelectable, selectableDownOfTopRight, "Wrong selectable to Bottom of top Right Selectable"); }
private void switchSelectedDown() { Selectable next = selectable.FindSelectableOnDown(); if (next != null) { EventSystem.current.SetSelectedGameObject(next.gameObject); } }
static int FindSelectableOnDown(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); Selectable obj = LuaScriptMgr.GetUnityObject <Selectable>(L, 1); Selectable o = obj.FindSelectableOnDown(); LuaScriptMgr.Push(L, o); return(1); }
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(); } } } } } }
protected override void OnSwipeDown() { base.OnSwipeDown(); var tmp = m_currentSelectable.FindSelectableOnDown(); m_currentSelectable = tmp ? tmp : m_currentSelectable; m_currentSelectable.Select(); }
// 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(); } } }
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(); } }
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); }
// 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 }
private Selectable FindDown(Selectable current) { if (this.traversed.Contains(current)) { return(null); } this.traversed.Add(current); Selectable selectable = current.FindSelectableOnDown(); return(!this.IsValidSelectable(selectable) ? this.FindDown(selectable) : selectable); }
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); }