using UnityEngine.EventSystems; namespace UnityEngine.XR.Interaction.Toolkit.UI { /// /// Represents the state of a navigation in the Unity UI (UGUI) system. Keeps track of various book-keeping regarding UI selection, and move and button states. /// struct NavigationModel { public struct ImplementationData { /// /// Bookkeeping value for Unity UI (UGUI) that tracks the number of sequential move commands in the same direction that have been sent. Used to handle proper repeat timing. /// public int consecutiveMoveCount { get; set; } /// /// Bookkeeping value for Unity UI (UGUI) that tracks the direction of the last move command. Used to handle proper repeat timing. /// public MoveDirection lastMoveDirection { get; set; } /// /// Bookkeeping value for Unity UI (UGUI) that tracks the last time a move command was sent. Used to handle proper repeat timing. /// public float lastMoveTime { get; set; } /// /// Resets this object to its default, unused state. /// public void Reset() { consecutiveMoveCount = 0; lastMoveTime = 0.0f; lastMoveDirection = MoveDirection.None; } } /// /// A 2D Vector that represents the up/down/left/right movement to apply to UI selection, such as moving up and down in options menus or highlighting options. /// public Vector2 move { get; set; } /// /// Tracks the current state of the submit or 'move forward' button. Setting this also updates the to track if a press or release occurred in the frame. /// public bool submitButtonDown { get => m_SubmitButtonDown; set { if (m_SubmitButtonDown != value) { submitButtonDelta = value ? ButtonDeltaState.Pressed : ButtonDeltaState.Released; m_SubmitButtonDown = value; } } } /// /// Tracks the changes in between calls to . /// internal ButtonDeltaState submitButtonDelta { get; private set; } /// /// Tracks the current state of the cancel or 'move backward' button. Setting this also updates the to track if a press or release occurred in the frame. /// public bool cancelButtonDown { get => m_CancelButtonDown; set { if (m_CancelButtonDown != value) { cancelButtonDelta = value ? ButtonDeltaState.Pressed : ButtonDeltaState.Released; m_CancelButtonDown = value; } } } /// /// Tracks the changes in between calls to . /// internal ButtonDeltaState cancelButtonDelta { get; private set; } /// /// Internal bookkeeping data used by the Unity UI (UGUI) system. /// internal ImplementationData implementationData { get; set; } /// /// Resets this object to it's default, unused state. /// public void Reset() { move = Vector2.zero; m_SubmitButtonDown = m_CancelButtonDown = false; submitButtonDelta = cancelButtonDelta = ButtonDeltaState.NoChange; implementationData.Reset(); } /// /// Call this at the end of polling for per-frame changes. This resets delta values, such as and . /// public void OnFrameFinished() { submitButtonDelta = ButtonDeltaState.NoChange; cancelButtonDelta = ButtonDeltaState.NoChange; } bool m_SubmitButtonDown; bool m_CancelButtonDown; } }