|
5 | 5 |
|
6 | 6 | namespace Zigurous.UI
|
7 | 7 | {
|
| 8 | + /// <summary> |
| 9 | + /// Keeps track of a stack of selected game objects as to allow for easy |
| 10 | + /// back navigation. |
| 11 | + /// </summary> |
8 | 12 | [RequireComponent(typeof(EventSystem))]
|
9 | 13 | [AddComponentMenu("Zigurous/UI/Navigation/Navigation Stack")]
|
10 | 14 | public class NavigationStack : MonoBehaviour
|
11 | 15 | {
|
| 16 | + /// <summary> |
| 17 | + /// The event system being tracked by the navigation stack. |
| 18 | + /// </summary> |
12 | 19 | public EventSystem eventSystem { get; private set; }
|
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// The stack of game objects that have been selected. |
| 23 | + /// </summary> |
13 | 24 | public Stack<GameObject> navigationStack { get; private set; }
|
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// The current selected game object at the top of the stack. |
| 28 | + /// </summary> |
14 | 29 | public GameObject CurrentSelectedGameObject => this.navigationStack.Peek();
|
15 |
| - public InputAction backInput; |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// The input action to handle navigating backwards in the stack by |
| 33 | + /// popping items off. |
| 34 | + /// </summary> |
| 35 | + [Tooltip("The input action to handle navigating backwards in the stack by popping items off.")] |
| 36 | + public InputAction backNavigationInput = new InputAction("MenuBackNavigation", InputActionType.Button); |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Allows for all items to be popped off the stack. Often times you |
| 40 | + /// want to maintain at least the root game object. |
| 41 | + /// </summary> |
| 42 | + [Tooltip("Allows for all items to be popped off the stack. Often times you want to maintain at least the root game object.")] |
16 | 43 | public bool allowEmptyStack = false;
|
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Allows for null game objects to be pushed onto the stack. |
| 47 | + /// </summary> |
| 48 | + [Tooltip("Allows for null game objects to be pushed onto the stack.")] |
17 | 49 | public bool allowNullSelections = false;
|
18 | 50 |
|
19 | 51 | private void Reset()
|
20 | 52 | {
|
21 |
| - this.backInput = new InputAction("MenuBackNavigation", InputActionType.Button); |
22 |
| - this.backInput.AddBinding("<Keyboard>/escape"); |
23 |
| - this.backInput.AddBinding("<Keyboard>/backspace"); |
24 |
| - this.backInput.AddBinding("<Gamepad>/select"); |
25 |
| - this.backInput.AddBinding("<Gamepad>/buttonEast"); |
| 53 | + this.backNavigationInput = new InputAction("MenuBackNavigation", InputActionType.Button); |
| 54 | + this.backNavigationInput.AddBinding("<Keyboard>/escape"); |
| 55 | + this.backNavigationInput.AddBinding("<Keyboard>/backspace"); |
| 56 | + this.backNavigationInput.AddBinding("<Gamepad>/select"); |
| 57 | + this.backNavigationInput.AddBinding("<Gamepad>/buttonEast"); |
26 | 58 | }
|
27 | 59 |
|
28 | 60 | private void Awake()
|
29 | 61 | {
|
30 | 62 | this.eventSystem = GetComponent<EventSystem>();
|
31 | 63 | this.navigationStack = new Stack<GameObject>(8);
|
| 64 | + this.backNavigationInput.performed += OnBack; |
32 | 65 | }
|
33 | 66 |
|
34 | 67 | private void OnEnable()
|
35 | 68 | {
|
36 |
| - this.backInput.Enable(); |
37 |
| - this.backInput.performed += OnBack; |
| 69 | + this.backNavigationInput.Enable(); |
38 | 70 | }
|
39 | 71 |
|
40 | 72 | private void OnDisable()
|
41 | 73 | {
|
42 |
| - this.backInput.Disable(); |
43 |
| - this.backInput.performed -= OnBack; |
| 74 | + this.backNavigationInput.Disable(); |
44 | 75 | }
|
45 | 76 |
|
46 | 77 | private void Update()
|
|
0 commit comments