forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseInputModule.cs
More file actions
254 lines (230 loc) · 5.91 KB
/
Copy pathBaseInputModule.cs
File metadata and controls
254 lines (230 loc) · 5.91 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using System;
using System.Collections.Generic;
namespace UnityEngine.EventSystems
{
[RequireComponent(typeof(EventSystem))]
public abstract class BaseInputModule : UIBehaviour
{
[NonSerialized]
protected List<RaycastResult> m_RaycastResultCache = new List<RaycastResult>();
private AxisEventData m_AxisEventData;
private EventSystem m_EventSystem;
private BaseEventData m_BaseEventData;
protected BaseInput m_InputOverride;
private BaseInput m_DefaultInput;
public BaseInput input
{
get
{
BaseInput result;
if (this.m_InputOverride != null)
{
result = this.m_InputOverride;
}
else
{
if (this.m_DefaultInput == null)
{
BaseInput[] components = base.GetComponents<BaseInput>();
BaseInput[] array = components;
for (int i = 0; i < array.Length; i++)
{
BaseInput baseInput = array[i];
if (baseInput != null && baseInput.GetType() == typeof(BaseInput))
{
this.m_DefaultInput = baseInput;
break;
}
}
if (this.m_DefaultInput == null)
{
this.m_DefaultInput = base.gameObject.AddComponent<BaseInput>();
}
}
result = this.m_DefaultInput;
}
return result;
}
}
protected EventSystem eventSystem
{
get
{
return this.m_EventSystem;
}
}
protected override void OnEnable()
{
base.OnEnable();
this.m_EventSystem = base.GetComponent<EventSystem>();
this.m_EventSystem.UpdateModules();
}
protected override void OnDisable()
{
this.m_EventSystem.UpdateModules();
base.OnDisable();
}
public abstract void Process();
protected static RaycastResult FindFirstRaycast(List<RaycastResult> candidates)
{
RaycastResult result;
for (int i = 0; i < candidates.Count; i++)
{
if (!(candidates[i].gameObject == null))
{
result = candidates[i];
return result;
}
}
result = default(RaycastResult);
return result;
}
protected static MoveDirection DetermineMoveDirection(float x, float y)
{
return BaseInputModule.DetermineMoveDirection(x, y, 0.6f);
}
protected static MoveDirection DetermineMoveDirection(float x, float y, float deadZone)
{
Vector2 vector = new Vector2(x, y);
MoveDirection result;
if (vector.sqrMagnitude < deadZone * deadZone)
{
result = MoveDirection.None;
}
else if (Mathf.Abs(x) > Mathf.Abs(y))
{
if (x > 0f)
{
result = MoveDirection.Right;
}
else
{
result = MoveDirection.Left;
}
}
else if (y > 0f)
{
result = MoveDirection.Up;
}
else
{
result = MoveDirection.Down;
}
return result;
}
protected static GameObject FindCommonRoot(GameObject g1, GameObject g2)
{
GameObject result;
if (g1 == null || g2 == null)
{
result = null;
}
else
{
Transform transform = g1.transform;
while (transform != null)
{
Transform transform2 = g2.transform;
while (transform2 != null)
{
if (transform == transform2)
{
result = transform.gameObject;
return result;
}
transform2 = transform2.parent;
}
transform = transform.parent;
}
result = null;
}
return result;
}
protected void HandlePointerExitAndEnter(PointerEventData currentPointerData, GameObject newEnterTarget)
{
if (newEnterTarget == null || currentPointerData.pointerEnter == null)
{
for (int i = 0; i < currentPointerData.hovered.Count; i++)
{
ExecuteEvents.Execute<IPointerExitHandler>(currentPointerData.hovered[i], currentPointerData, ExecuteEvents.pointerExitHandler);
}
currentPointerData.hovered.Clear();
if (newEnterTarget == null)
{
currentPointerData.pointerEnter = newEnterTarget;
return;
}
}
if (!(currentPointerData.pointerEnter == newEnterTarget) || !newEnterTarget)
{
GameObject gameObject = BaseInputModule.FindCommonRoot(currentPointerData.pointerEnter, newEnterTarget);
if (currentPointerData.pointerEnter != null)
{
Transform transform = currentPointerData.pointerEnter.transform;
while (transform != null)
{
if (gameObject != null && gameObject.transform == transform)
{
break;
}
ExecuteEvents.Execute<IPointerExitHandler>(transform.gameObject, currentPointerData, ExecuteEvents.pointerExitHandler);
currentPointerData.hovered.Remove(transform.gameObject);
transform = transform.parent;
}
}
currentPointerData.pointerEnter = newEnterTarget;
if (newEnterTarget != null)
{
Transform transform2 = newEnterTarget.transform;
while (transform2 != null && transform2.gameObject != gameObject)
{
ExecuteEvents.Execute<IPointerEnterHandler>(transform2.gameObject, currentPointerData, ExecuteEvents.pointerEnterHandler);
currentPointerData.hovered.Add(transform2.gameObject);
transform2 = transform2.parent;
}
}
}
}
protected virtual AxisEventData GetAxisEventData(float x, float y, float moveDeadZone)
{
if (this.m_AxisEventData == null)
{
this.m_AxisEventData = new AxisEventData(this.eventSystem);
}
this.m_AxisEventData.Reset();
this.m_AxisEventData.moveVector = new Vector2(x, y);
this.m_AxisEventData.moveDir = BaseInputModule.DetermineMoveDirection(x, y, moveDeadZone);
return this.m_AxisEventData;
}
protected virtual BaseEventData GetBaseEventData()
{
if (this.m_BaseEventData == null)
{
this.m_BaseEventData = new BaseEventData(this.eventSystem);
}
this.m_BaseEventData.Reset();
return this.m_BaseEventData;
}
public virtual bool IsPointerOverGameObject(int pointerId)
{
return false;
}
public virtual bool ShouldActivateModule()
{
return base.enabled && base.gameObject.activeInHierarchy;
}
public virtual void DeactivateModule()
{
}
public virtual void ActivateModule()
{
}
public virtual void UpdateModule()
{
}
public virtual bool IsModuleSupported()
{
return true;
}
}
}