using System;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
[Serializable]
///
/// Structure storing details related to navigation.
///
public struct Navigation : IEquatable
{
/*
* This looks like it's not flags, but it is flags,
* the reason is that Automatic is considered horizontal
* and verical mode combined
*/
[Flags]
///
/// Navigation mode enumeration.
///
///
/// This looks like it's not flags, but it is flags, the reason is that Automatic is considered horizontal and vertical mode combined
///
///
///
///
///
///
public enum Mode
{
///
/// No navigation is allowed from this object.
///
None = 0,
///
/// Horizontal Navigation.
///
///
/// Navigation should only be allowed when left / right move events happen.
///
Horizontal = 1,
///
/// Vertical navigation.
///
///
/// Navigation should only be allowed when up / down move events happen.
///
Vertical = 2,
///
/// Automatic navigation.
///
///
/// Attempt to find the 'best' next object to select. This should be based on a sensible heuristic.
///
Automatic = 3,
///
/// Explicit navigation.
///
///
/// User should explicitly specify what is selected by each move event.
///
Explicit = 4,
}
// Which method of navigation will be used.
[SerializeField]
private Mode m_Mode;
[Tooltip("Enables navigation to wrap around from last to first or first to last element. Does not work for automatic grid navigation")]
[SerializeField]
private bool m_WrapAround;
// Game object selected when the joystick moves up. Used when navigation is set to "Explicit".
[SerializeField]
private Selectable m_SelectOnUp;
// Game object selected when the joystick moves down. Used when navigation is set to "Explicit".
[SerializeField]
private Selectable m_SelectOnDown;
// Game object selected when the joystick moves left. Used when navigation is set to "Explicit".
[SerializeField]
private Selectable m_SelectOnLeft;
// Game object selected when the joystick moves right. Used when navigation is set to "Explicit".
[SerializeField]
private Selectable m_SelectOnRight;
///
/// Navigation mode.
///
public Mode mode { get { return m_Mode; } set { m_Mode = value; } }
///
/// Enables navigation to wrap around from last to first or first to last element.
/// Will find the furthest element from the current element in the opposite direction of movement.
///
///
/// Note: If you have a grid of elements and you are on the last element in a row it will not wrap over to the next row it will pick the furthest element in the opposite direction.
///
public bool wrapAround { get { return m_WrapAround; } set { m_WrapAround = value; } }
///
/// Specify a Selectable UI GameObject to highlight when the Up arrow key is pressed.
///
///
///
///
///
///
public Selectable selectOnUp { get { return m_SelectOnUp; } set { m_SelectOnUp = value; } }
///
/// Specify a Selectable UI GameObject to highlight when the down arrow key is pressed.
///
///
///
///
///
///
public Selectable selectOnDown { get { return m_SelectOnDown; } set { m_SelectOnDown = value; } }
///
/// Specify a Selectable UI GameObject to highlight when the left arrow key is pressed.
///
///
///
///
///
///
public Selectable selectOnLeft { get { return m_SelectOnLeft; } set { m_SelectOnLeft = value; } }
///
/// Specify a Selectable UI GameObject to highlight when the right arrow key is pressed.
///
///
///
///
///
///
public Selectable selectOnRight { get { return m_SelectOnRight; } set { m_SelectOnRight = value; } }
///
/// Return a Navigation with sensible default values.
///
///
///
///
///
///
static public Navigation defaultNavigation
{
get
{
var defaultNav = new Navigation();
defaultNav.m_Mode = Mode.Automatic;
defaultNav.m_WrapAround = false;
return defaultNav;
}
}
public bool Equals(Navigation other)
{
return mode == other.mode &&
selectOnUp == other.selectOnUp &&
selectOnDown == other.selectOnDown &&
selectOnLeft == other.selectOnLeft &&
selectOnRight == other.selectOnRight;
}
}
}