Skip to content

Commit 7dcd168

Browse files
committed
Add documentation comments
1 parent 0b9099d commit 7dcd168

File tree

3 files changed

+101
-16
lines changed

3 files changed

+101
-16
lines changed

Runtime/NavigationStack.cs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,73 @@
55

66
namespace Zigurous.UI
77
{
8+
/// <summary>
9+
/// Keeps track of a stack of selected game objects as to allow for easy
10+
/// back navigation.
11+
/// </summary>
812
[RequireComponent(typeof(EventSystem))]
913
[AddComponentMenu("Zigurous/UI/Navigation/Navigation Stack")]
1014
public class NavigationStack : MonoBehaviour
1115
{
16+
/// <summary>
17+
/// The event system being tracked by the navigation stack.
18+
/// </summary>
1219
public EventSystem eventSystem { get; private set; }
20+
21+
/// <summary>
22+
/// The stack of game objects that have been selected.
23+
/// </summary>
1324
public Stack<GameObject> navigationStack { get; private set; }
25+
26+
/// <summary>
27+
/// The current selected game object at the top of the stack.
28+
/// </summary>
1429
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.")]
1643
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.")]
1749
public bool allowNullSelections = false;
1850

1951
private void Reset()
2052
{
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");
2658
}
2759

2860
private void Awake()
2961
{
3062
this.eventSystem = GetComponent<EventSystem>();
3163
this.navigationStack = new Stack<GameObject>(8);
64+
this.backNavigationInput.performed += OnBack;
3265
}
3366

3467
private void OnEnable()
3568
{
36-
this.backInput.Enable();
37-
this.backInput.performed += OnBack;
69+
this.backNavigationInput.Enable();
3870
}
3971

4072
private void OnDisable()
4173
{
42-
this.backInput.Disable();
43-
this.backInput.performed -= OnBack;
74+
this.backNavigationInput.Disable();
4475
}
4576

4677
private void Update()

Runtime/ScrollToSelection.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,61 @@
55

66
namespace Zigurous.UI
77
{
8+
/// <summary>
9+
/// Handles scrolling a ScrollRect component to the selected child element.
10+
/// This is especially useful for controller support.
11+
/// </summary>
812
[RequireComponent(typeof(ScrollRect))]
913
[AddComponentMenu("Zigurous/UI/Navigation/Scroll To Selection")]
1014
public class ScrollToSelection : MonoBehaviour
1115
{
16+
/// <summary>
17+
/// A scroll direction type.
18+
/// </summary>
1219
public enum ScrollDirection
1320
{
1421
Vertical,
1522
Horizontal,
1623
Both,
1724
}
1825

26+
/// <summary>
27+
/// The direction to scroll the ScrollRect.
28+
/// </summary>
29+
[Tooltip("The direction to scroll the ScrollRect.")]
1930
public ScrollDirection scrollDirection;
31+
32+
/// <summary>
33+
/// How quickly the ScrollRect scrolls.
34+
/// </summary>
35+
[Tooltip("How quickly the ScrollRect scrolls.")]
2036
public float scrollSpeed = 10.0f;
37+
38+
/// <summary>
39+
/// Whether the ScrollRect is currently being manually scrolled. This
40+
/// allows the user to scroll freely with the mouse even when a child
41+
/// element is selected.
42+
/// </summary>
2143
public bool manualScrolling { get; private set; }
2244

45+
/// <summary>
46+
/// The ScrollRect component being scrolled.
47+
/// </summary>
2348
public ScrollRect scrollRect { get; private set; }
49+
50+
/// <summary>
51+
/// The RectTransform component of the scroll rect.
52+
/// </summary>
2453
public RectTransform scrollTransform { get; private set; }
54+
55+
/// <summary>
56+
/// The current selected game object.
57+
/// </summary>
2558
public GameObject selectedGameObject { get; private set; }
59+
60+
/// <summary>
61+
/// The RectTransform of the current selected game object.
62+
/// </summary>
2663
public RectTransform selectedTransform { get; private set; }
2764

2865
private void Awake()

Runtime/ScrollWithInput.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,29 @@
55

66
namespace Zigurous.UI
77
{
8+
/// <summary>
9+
/// Handles scrolling a ScrollRect component with user input. This is
10+
/// especially useful for controller support.
11+
/// </summary>
812
[RequireComponent(typeof(ScrollRect))]
913
[AddComponentMenu("Zigurous/UI/Navigation/Scroll With Input")]
1014
public class ScrollWithInput : MonoBehaviour
1115
{
12-
private ScrollRect _scrollRect;
13-
public InputAction scrollInput;
16+
/// <summary>
17+
/// The ScrollRect component being scrolled.
18+
/// </summary>
19+
public ScrollRect scrollRect { get; private set; }
20+
21+
/// <summary>
22+
/// The input action that handles scrolling.
23+
/// </summary>
24+
[Tooltip("The input action that handles scrolling.")]
25+
public InputAction scrollInput = new InputAction("ScrollInput", InputActionType.Value, null, null, null, "Vector2");
26+
27+
/// <summary>
28+
/// The sensitivity multiplier applied to the input.
29+
/// </summary>
30+
[Tooltip("The sensitivity multiplier applied to the input.")]
1431
public float sensitivity = 1.0f;
1532

1633
private void Reset()
@@ -23,7 +40,7 @@ private void Reset()
2340

2441
private void Awake()
2542
{
26-
_scrollRect = GetComponent<ScrollRect>();
43+
this.scrollRect = GetComponent<ScrollRect>();
2744
}
2845

2946
private void OnEnable()
@@ -44,11 +61,11 @@ private void Update()
4461
return;
4562
}
4663

47-
if (eventSystem.currentSelectedGameObject == _scrollRect.gameObject ||
48-
eventSystem.currentSelectedGameObject.transform.parent == _scrollRect.content)
64+
if (eventSystem.currentSelectedGameObject == this.scrollRect.gameObject ||
65+
eventSystem.currentSelectedGameObject.transform.parent == this.scrollRect.content)
4966
{
5067
Vector2 input = this.scrollInput.ReadValue<Vector2>();
51-
_scrollRect.normalizedPosition += input * this.sensitivity * Time.unscaledDeltaTime;
68+
this.scrollRect.normalizedPosition += input * this.sensitivity * Time.unscaledDeltaTime;
5269
}
5370
}
5471

0 commit comments

Comments
 (0)