A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3
4namespace UnityEditor.U2D.Common.Path.GUIFramework
5{
6 /// <summary>
7 /// Represents a generic UI control.
8 /// </summary>
9 internal class GenericControl : Control
10 {
11 /// <summary>
12 /// Func for OnBeginLayout
13 /// </summary>
14 public Func<IGUIState, LayoutData> onBeginLayout;
15 /// <summary>
16 /// Action for OnEndLayout
17 /// </summary>
18 public Action<IGUIState> onEndLayout;
19 /// <summary>
20 /// Action for OnRepaint
21 /// </summary>
22 public Action<IGUIState, Control, int> onRepaint;
23 /// <summary>
24 /// Func for GetCount
25 /// </summary>
26 public Func<int> count;
27 /// <summary>
28 /// Func for GetPosition
29 /// </summary>
30 public Func<int, Vector3> position;
31 /// <summary>
32 /// Func for GetDistance
33 /// </summary>
34 public Func<IGUIState, int, float> distance;
35 /// <summary>
36 /// Func for GetForward
37 /// </summary>
38 public Func<int, Vector3> forward;
39 /// <summary>
40 /// Func for GetUp
41 /// </summary>
42 public Func<int, Vector3> up;
43 /// <summary>
44 /// Func for GetRight
45 /// </summary>
46 public Func<int, Vector3> right;
47 /// <summary>
48 /// Func for GetUserData
49 /// </summary>
50 public Func<int, object> userData;
51
52 /// <summary>
53 /// Initializes and returns an instance of GenericControl
54 /// </summary>
55 /// <param name="name">The name of the generic control.</param>
56 public GenericControl(string name) : base(name)
57 {
58 }
59
60
61 /// <summary>
62 /// Gets the number of sub-controllers.
63 /// </summary>
64 /// <remarks>
65 /// By default, this is `1`. If you implement your own controller and want to use multiple sub-controllers within it, you can assign getCount to a function that returns the number of sub-controllers.
66 /// </remarks>
67 /// <returns>Returns the number of sub-controllers. If you do not assign getCount, this returns 1.</returns>
68 protected override int GetCount()
69 {
70 if (count != null)
71 return count();
72
73 return base.GetCount();
74 }
75
76 /// <summary>
77 /// Called when the control ends its layout.
78 /// </summary>
79 /// <param name="guiState">The current state of the custom editor.</param>
80 protected override void OnEndLayout(IGUIState guiState)
81 {
82 if (onEndLayout != null)
83 onEndLayout(guiState);
84 }
85
86 /// <summary>
87 /// Called when the control repaints its contents.
88 /// </summary>
89 /// <param name="guiState">The current state of the custom editor.</param>
90 /// <param name="index">Current Index</param>
91 protected override void OnRepaint(IGUIState guiState, int index)
92 {
93 if (onRepaint != null)
94 onRepaint(guiState, this, index);
95 }
96
97 /// <summary>
98 /// Called when the control begins its layout.
99 /// </summary>
100 /// <param name="data">The layout data.</param>
101 /// <param name="guiState">The current state of the custom editor.</param>
102 /// <returns>The LayoutData</returns>
103 protected override LayoutData OnBeginLayout(LayoutData data, IGUIState guiState)
104 {
105 if (onBeginLayout != null)
106 return onBeginLayout(guiState);
107
108 return data;
109 }
110
111 /// <summary>
112 /// Gets the position of the control.
113 /// </summary>
114 /// <param name="guiState">The current state of the custom editor.</param>
115 /// <param name="index">The Index</param>
116 /// <returns>The position</returns>
117 protected override Vector3 GetPosition(IGUIState guiState, int index)
118 {
119 if (position != null)
120 return position(index);
121
122 return base.GetPosition(guiState,index);
123 }
124
125 /// <summary>
126 /// Gets the distance from the Scene view camera to the control.
127 /// </summary>
128 /// <param name="guiState">The current state of the custom editor.</param>
129 /// <param name="index">The Index</param>
130 /// <returns>Returns the distance from the Scene view camera to the control.</returns>
131 protected override float GetDistance(IGUIState guiState, int index)
132 {
133 if (distance != null)
134 return distance(guiState, index);
135
136 return base.GetDistance(guiState, index);
137 }
138
139 /// <summary>
140 /// Gets the forward vector of the control.
141 /// </summary>
142 /// <param name="guiState">The current state of the custom editor.</param>
143 /// <param name="index">The Index</param>
144 /// <returns>Returns the generic control's forward vector.</returns>
145 protected override Vector3 GetForward(IGUIState guiState, int index)
146 {
147 if (forward != null)
148 return forward(index);
149
150 return base.GetForward(guiState,index);
151 }
152
153 /// <summary>
154 /// Gets the up vector of the control.
155 /// </summary>
156 /// <param name="guiState">The current state of the custom editor.</param>
157 /// <param name="index">The Index</param>
158 /// <returns>Returns the generic control's up vector.</returns>
159 protected override Vector3 GetUp(IGUIState guiState, int index)
160 {
161 if (up != null)
162 return up(index);
163
164 return base.GetUp(guiState,index);
165 }
166
167 /// <summary>
168 /// Gets the right vector of the control.
169 /// </summary>
170 /// <param name="guiState">The current state of the custom editor.</param>
171 /// <param name="index">The Index</param>
172 /// <returns>Returns the generic control's right vector.</returns>
173 protected override Vector3 GetRight(IGUIState guiState, int index)
174 {
175 if (right != null)
176 return right(index);
177
178 return base.GetRight(guiState,index);
179 }
180
181 /// <summary>
182 /// Override for GetUserData
183 /// </summary>
184 /// <param name="guiState">The current state of the custom editor.</param>
185 /// <param name="index">The Index</param>
186 /// <returns>Return the user data</returns>
187 protected override object GetUserData(IGUIState guiState, int index)
188 {
189 if (userData != null)
190 return userData(index);
191
192 return base.GetUserData(guiState,index);
193 }
194 }
195}