-
Notifications
You must be signed in to change notification settings - Fork 866
Expand file tree
/
Copy pathDebugUIHandlerWidget.cs
More file actions
140 lines (119 loc) · 4.08 KB
/
DebugUIHandlerWidget.cs
File metadata and controls
140 lines (119 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
namespace UnityEngine.Rendering.UI
{
/// <summary>
/// Base class for handling UI actions for widgets.
/// </summary>
public class DebugUIHandlerWidget : MonoBehaviour
{
/// <summary>
/// Default widget color.
/// </summary>
[HideInInspector]
public Color colorDefault = new Color(0.8f, 0.8f, 0.8f, 1f);
/// <summary>
/// Selected widget color.
/// </summary>
[HideInInspector]
public Color colorSelected = new Color(0.25f, 0.65f, 0.8f, 1f);
/// <summary>
/// Parent widget UI Handler.
/// </summary>
public DebugUIHandlerWidget parentUIHandler { get; set; }
/// <summary>
/// Previous widget UI Handler.
/// </summary>
public DebugUIHandlerWidget previousUIHandler { get; set; }
/// <summary>
/// Next widget UI Handler.
/// </summary>
public DebugUIHandlerWidget nextUIHandler { get; set; }
/// <summary>
/// Associated widget.
/// </summary>
protected DebugUI.Widget m_Widget;
/// <summary>
/// OnEnable implementation.
/// </summary>
protected virtual void OnEnable() { }
internal virtual void SetWidget(DebugUI.Widget widget)
{
m_Widget = widget;
}
internal DebugUI.Widget GetWidget()
{
return m_Widget;
}
/// <summary>
/// Casts the widget to the correct type.
/// </summary>
/// <typeparam name="T">Type of the widget.</typeparam>
/// <returns>Properly cast reference to the widget.</returns>
protected T CastWidget<T>()
where T : DebugUI.Widget
{
var casted = m_Widget as T;
string typeName = m_Widget == null ? "null" : m_Widget.GetType().ToString();
if (casted == null)
throw new InvalidOperationException("Can't cast " + typeName + " to " + typeof(T));
return casted;
}
/// <summary>
/// OnSelection implementation.
/// </summary>
/// <param name="fromNext">True if the selection wrapped around.</param>
/// <param name="previous">Previous widget.</param>
/// <returns>True if the selection is allowed.</returns>
public virtual bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
{
return true;
}
/// <summary>
/// OnDeselection implementation.
/// </summary>
public virtual void OnDeselection() { }
/// <summary>
/// OnAction implementation.
/// </summary>
public virtual void OnAction() { }
/// <summary>
/// OnIncrement implementation.
/// </summary>
/// <param name="fast">True if incrementing fast.</param>
public virtual void OnIncrement(bool fast) { }
/// <summary>
/// OnDecrement implementation.
/// </summary>
/// <param name="fast">Trye if decrementing fast.</param>
public virtual void OnDecrement(bool fast) { }
/// <summary>
/// Previous implementation.
/// </summary>
/// <returns>Previous widget UI handler, parent if there is none.</returns>
public virtual DebugUIHandlerWidget Previous()
{
return previousUIHandler != null ? previousUIHandler : parentUIHandler;
}
/// <summary>
/// Next implementation.
/// </summary>
/// <returns>Next widget UI handler, parent if there is none.</returns>
public virtual DebugUIHandlerWidget Next()
{
if (nextUIHandler != null)
return nextUIHandler;
if (parentUIHandler != null)
{
var p = parentUIHandler;
while (p != null)
{
var n = p.nextUIHandler;
if (n != null)
return n;
p = p.parentUIHandler;
}
}
return null;
}
}
}