forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointerInputModule.cs
More file actions
346 lines (312 loc) · 10.7 KB
/
Copy pathPointerInputModule.cs
File metadata and controls
346 lines (312 loc) · 10.7 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
using System;
using System.Collections.Generic;
using System.Text;
namespace UnityEngine.EventSystems
{
public abstract class PointerInputModule : BaseInputModule
{
protected class ButtonState
{
private PointerEventData.InputButton m_Button = PointerEventData.InputButton.Left;
private PointerInputModule.MouseButtonEventData m_EventData;
public PointerInputModule.MouseButtonEventData eventData
{
get
{
return this.m_EventData;
}
set
{
this.m_EventData = value;
}
}
public PointerEventData.InputButton button
{
get
{
return this.m_Button;
}
set
{
this.m_Button = value;
}
}
}
protected class MouseState
{
private List<PointerInputModule.ButtonState> m_TrackedButtons = new List<PointerInputModule.ButtonState>();
public bool AnyPressesThisFrame()
{
bool result;
for (int i = 0; i < this.m_TrackedButtons.Count; i++)
{
if (this.m_TrackedButtons[i].eventData.PressedThisFrame())
{
result = true;
return result;
}
}
result = false;
return result;
}
public bool AnyReleasesThisFrame()
{
bool result;
for (int i = 0; i < this.m_TrackedButtons.Count; i++)
{
if (this.m_TrackedButtons[i].eventData.ReleasedThisFrame())
{
result = true;
return result;
}
}
result = false;
return result;
}
public PointerInputModule.ButtonState GetButtonState(PointerEventData.InputButton button)
{
PointerInputModule.ButtonState buttonState = null;
for (int i = 0; i < this.m_TrackedButtons.Count; i++)
{
if (this.m_TrackedButtons[i].button == button)
{
buttonState = this.m_TrackedButtons[i];
break;
}
}
if (buttonState == null)
{
buttonState = new PointerInputModule.ButtonState
{
button = button,
eventData = new PointerInputModule.MouseButtonEventData()
};
this.m_TrackedButtons.Add(buttonState);
}
return buttonState;
}
public void SetButtonState(PointerEventData.InputButton button, PointerEventData.FramePressState stateForMouseButton, PointerEventData data)
{
PointerInputModule.ButtonState buttonState = this.GetButtonState(button);
buttonState.eventData.buttonState = stateForMouseButton;
buttonState.eventData.buttonData = data;
}
}
public class MouseButtonEventData
{
public PointerEventData.FramePressState buttonState;
public PointerEventData buttonData;
public bool PressedThisFrame()
{
return this.buttonState == PointerEventData.FramePressState.Pressed || this.buttonState == PointerEventData.FramePressState.PressedAndReleased;
}
public bool ReleasedThisFrame()
{
return this.buttonState == PointerEventData.FramePressState.Released || this.buttonState == PointerEventData.FramePressState.PressedAndReleased;
}
}
public const int kMouseLeftId = -1;
public const int kMouseRightId = -2;
public const int kMouseMiddleId = -3;
public const int kFakeTouchesId = -4;
protected Dictionary<int, PointerEventData> m_PointerData = new Dictionary<int, PointerEventData>();
private readonly PointerInputModule.MouseState m_MouseState = new PointerInputModule.MouseState();
protected bool GetPointerData(int id, out PointerEventData data, bool create)
{
bool result;
if (!this.m_PointerData.TryGetValue(id, out data) && create)
{
data = new PointerEventData(base.eventSystem)
{
pointerId = id
};
this.m_PointerData.Add(id, data);
result = true;
}
else
{
result = false;
}
return result;
}
protected void RemovePointerData(PointerEventData data)
{
this.m_PointerData.Remove(data.pointerId);
}
protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
{
PointerEventData pointerEventData;
bool pointerData = this.GetPointerData(input.fingerId, out pointerEventData, true);
pointerEventData.Reset();
pressed = (pointerData || input.phase == TouchPhase.Began);
released = (input.phase == TouchPhase.Canceled || input.phase == TouchPhase.Ended);
if (pointerData)
{
pointerEventData.position = input.position;
}
if (pressed)
{
pointerEventData.delta = Vector2.zero;
}
else
{
pointerEventData.delta = input.position - pointerEventData.position;
}
pointerEventData.position = input.position;
pointerEventData.button = PointerEventData.InputButton.Left;
base.eventSystem.RaycastAll(pointerEventData, this.m_RaycastResultCache);
RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);
pointerEventData.pointerCurrentRaycast = pointerCurrentRaycast;
this.m_RaycastResultCache.Clear();
return pointerEventData;
}
protected void CopyFromTo(PointerEventData from, PointerEventData to)
{
to.position = from.position;
to.delta = from.delta;
to.scrollDelta = from.scrollDelta;
to.pointerCurrentRaycast = from.pointerCurrentRaycast;
to.pointerEnter = from.pointerEnter;
}
protected PointerEventData.FramePressState StateForMouseButton(int buttonId)
{
bool mouseButtonDown = base.input.GetMouseButtonDown(buttonId);
bool mouseButtonUp = base.input.GetMouseButtonUp(buttonId);
PointerEventData.FramePressState result;
if (mouseButtonDown && mouseButtonUp)
{
result = PointerEventData.FramePressState.PressedAndReleased;
}
else if (mouseButtonDown)
{
result = PointerEventData.FramePressState.Pressed;
}
else if (mouseButtonUp)
{
result = PointerEventData.FramePressState.Released;
}
else
{
result = PointerEventData.FramePressState.NotChanged;
}
return result;
}
protected virtual PointerInputModule.MouseState GetMousePointerEventData()
{
return this.GetMousePointerEventData(0);
}
protected virtual PointerInputModule.MouseState GetMousePointerEventData(int id)
{
PointerEventData pointerEventData;
bool pointerData = this.GetPointerData(-1, out pointerEventData, true);
pointerEventData.Reset();
if (pointerData)
{
pointerEventData.position = base.input.mousePosition;
}
Vector2 mousePosition = base.input.mousePosition;
if (Cursor.lockState == CursorLockMode.Locked)
{
pointerEventData.position = new Vector2(-1f, -1f);
pointerEventData.delta = Vector2.zero;
}
else
{
pointerEventData.delta = mousePosition - pointerEventData.position;
pointerEventData.position = mousePosition;
}
pointerEventData.scrollDelta = base.input.mouseScrollDelta;
pointerEventData.button = PointerEventData.InputButton.Left;
base.eventSystem.RaycastAll(pointerEventData, this.m_RaycastResultCache);
RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);
pointerEventData.pointerCurrentRaycast = pointerCurrentRaycast;
this.m_RaycastResultCache.Clear();
PointerEventData pointerEventData2;
this.GetPointerData(-2, out pointerEventData2, true);
this.CopyFromTo(pointerEventData, pointerEventData2);
pointerEventData2.button = PointerEventData.InputButton.Right;
PointerEventData pointerEventData3;
this.GetPointerData(-3, out pointerEventData3, true);
this.CopyFromTo(pointerEventData, pointerEventData3);
pointerEventData3.button = PointerEventData.InputButton.Middle;
this.m_MouseState.SetButtonState(PointerEventData.InputButton.Left, this.StateForMouseButton(0), pointerEventData);
this.m_MouseState.SetButtonState(PointerEventData.InputButton.Right, this.StateForMouseButton(1), pointerEventData2);
this.m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, this.StateForMouseButton(2), pointerEventData3);
return this.m_MouseState;
}
protected PointerEventData GetLastPointerEventData(int id)
{
PointerEventData result;
this.GetPointerData(id, out result, false);
return result;
}
private static bool ShouldStartDrag(Vector2 pressPos, Vector2 currentPos, float threshold, bool useDragThreshold)
{
return !useDragThreshold || (pressPos - currentPos).sqrMagnitude >= threshold * threshold;
}
protected virtual void ProcessMove(PointerEventData pointerEvent)
{
GameObject newEnterTarget = (Cursor.lockState != CursorLockMode.Locked) ? pointerEvent.pointerCurrentRaycast.gameObject : null;
base.HandlePointerExitAndEnter(pointerEvent, newEnterTarget);
}
protected virtual void ProcessDrag(PointerEventData pointerEvent)
{
if (pointerEvent.IsPointerMoving() && Cursor.lockState != CursorLockMode.Locked && !(pointerEvent.pointerDrag == null))
{
if (!pointerEvent.dragging && PointerInputModule.ShouldStartDrag(pointerEvent.pressPosition, pointerEvent.position, (float)base.eventSystem.pixelDragThreshold, pointerEvent.useDragThreshold))
{
ExecuteEvents.Execute<IBeginDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler);
pointerEvent.dragging = true;
}
if (pointerEvent.dragging)
{
if (pointerEvent.pointerPress != pointerEvent.pointerDrag)
{
ExecuteEvents.Execute<IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
pointerEvent.eligibleForClick = false;
pointerEvent.pointerPress = null;
pointerEvent.rawPointerPress = null;
}
ExecuteEvents.Execute<IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);
}
}
}
public override bool IsPointerOverGameObject(int pointerId)
{
PointerEventData lastPointerEventData = this.GetLastPointerEventData(pointerId);
return lastPointerEventData != null && lastPointerEventData.pointerEnter != null;
}
protected void ClearSelection()
{
BaseEventData baseEventData = this.GetBaseEventData();
foreach (PointerEventData current in this.m_PointerData.Values)
{
base.HandlePointerExitAndEnter(current, null);
}
this.m_PointerData.Clear();
base.eventSystem.SetSelectedGameObject(null, baseEventData);
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder("<b>Pointer Input Module of type: </b>" + base.GetType());
stringBuilder.AppendLine();
foreach (KeyValuePair<int, PointerEventData> current in this.m_PointerData)
{
if (current.Value != null)
{
stringBuilder.AppendLine("<B>Pointer:</b> " + current.Key);
stringBuilder.AppendLine(current.Value.ToString());
}
}
return stringBuilder.ToString();
}
protected void DeselectIfSelectionChanged(GameObject currentOverGo, BaseEventData pointerEvent)
{
GameObject eventHandler = ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo);
if (eventHandler != base.eventSystem.currentSelectedGameObject)
{
base.eventSystem.SetSelectedGameObject(null, pointerEvent);
}
}
}
}