unity navigation input field tab shift-tab
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class TabNavigation : MonoBehaviour
{
void Update()
{
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));
}
}
}
}