forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTouchInputModule.cs
More file actions
247 lines (231 loc) · 6.98 KB
/
Copy pathTouchInputModule.cs
File metadata and controls
247 lines (231 loc) · 6.98 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
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.Serialization;
namespace UnityEngine.EventSystems
{
[Obsolete("TouchInputModule is no longer required as Touch input is now handled in StandaloneInputModule."), AddComponentMenu("Event/Touch Input Module")]
public class TouchInputModule : PointerInputModule
{
private Vector2 m_LastMousePosition;
private Vector2 m_MousePosition;
[FormerlySerializedAs("m_AllowActivationOnStandalone"), SerializeField]
private bool m_ForceModuleActive;
[Obsolete("allowActivationOnStandalone has been deprecated. Use forceModuleActive instead (UnityUpgradable) -> forceModuleActive")]
public bool allowActivationOnStandalone
{
get
{
return this.m_ForceModuleActive;
}
set
{
this.m_ForceModuleActive = value;
}
}
public bool forceModuleActive
{
get
{
return this.m_ForceModuleActive;
}
set
{
this.m_ForceModuleActive = value;
}
}
protected TouchInputModule()
{
}
public override void UpdateModule()
{
this.m_LastMousePosition = this.m_MousePosition;
this.m_MousePosition = base.input.mousePosition;
}
public override bool IsModuleSupported()
{
return this.forceModuleActive || base.input.touchSupported;
}
public override bool ShouldActivateModule()
{
bool result;
if (!base.ShouldActivateModule())
{
result = false;
}
else if (this.m_ForceModuleActive)
{
result = true;
}
else if (this.UseFakeInput())
{
bool flag = base.input.GetMouseButtonDown(0);
flag |= ((this.m_MousePosition - this.m_LastMousePosition).sqrMagnitude > 0f);
result = flag;
}
else
{
result = (base.input.touchCount > 0);
}
return result;
}
private bool UseFakeInput()
{
return !base.input.touchSupported;
}
public override void Process()
{
if (this.UseFakeInput())
{
this.FakeTouches();
}
else
{
this.ProcessTouchEvents();
}
}
private void FakeTouches()
{
PointerInputModule.MouseState mousePointerEventData = this.GetMousePointerEventData(0);
PointerInputModule.MouseButtonEventData eventData = mousePointerEventData.GetButtonState(PointerEventData.InputButton.Left).eventData;
if (eventData.PressedThisFrame())
{
eventData.buttonData.delta = Vector2.zero;
}
this.ProcessTouchPress(eventData.buttonData, eventData.PressedThisFrame(), eventData.ReleasedThisFrame());
if (base.input.GetMouseButton(0))
{
this.ProcessMove(eventData.buttonData);
this.ProcessDrag(eventData.buttonData);
}
}
private void ProcessTouchEvents()
{
for (int i = 0; i < base.input.touchCount; i++)
{
Touch touch = base.input.GetTouch(i);
if (touch.type != TouchType.Indirect)
{
bool pressed;
bool flag;
PointerEventData touchPointerEventData = base.GetTouchPointerEventData(touch, out pressed, out flag);
this.ProcessTouchPress(touchPointerEventData, pressed, flag);
if (!flag)
{
this.ProcessMove(touchPointerEventData);
this.ProcessDrag(touchPointerEventData);
}
else
{
base.RemovePointerData(touchPointerEventData);
}
}
}
}
protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released)
{
GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;
if (pressed)
{
pointerEvent.eligibleForClick = true;
pointerEvent.delta = Vector2.zero;
pointerEvent.dragging = false;
pointerEvent.useDragThreshold = true;
pointerEvent.pressPosition = pointerEvent.position;
pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;
base.DeselectIfSelectionChanged(gameObject, pointerEvent);
if (pointerEvent.pointerEnter != gameObject)
{
base.HandlePointerExitAndEnter(pointerEvent, gameObject);
pointerEvent.pointerEnter = gameObject;
}
GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy<IPointerDownHandler>(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler);
if (gameObject2 == null)
{
gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject);
}
float unscaledTime = Time.unscaledTime;
if (gameObject2 == pointerEvent.lastPress)
{
float num = unscaledTime - pointerEvent.clickTime;
if (num < 0.3f)
{
pointerEvent.clickCount++;
}
else
{
pointerEvent.clickCount = 1;
}
pointerEvent.clickTime = unscaledTime;
}
else
{
pointerEvent.clickCount = 1;
}
pointerEvent.pointerPress = gameObject2;
pointerEvent.rawPointerPress = gameObject;
pointerEvent.clickTime = unscaledTime;
pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(gameObject);
if (pointerEvent.pointerDrag != null)
{
ExecuteEvents.Execute<IInitializePotentialDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
}
}
if (released)
{
ExecuteEvents.Execute<IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
GameObject eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject);
if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick)
{
ExecuteEvents.Execute<IPointerClickHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
}
else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
{
ExecuteEvents.ExecuteHierarchy<IDropHandler>(gameObject, pointerEvent, ExecuteEvents.dropHandler);
}
pointerEvent.eligibleForClick = false;
pointerEvent.pointerPress = null;
pointerEvent.rawPointerPress = null;
if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
{
ExecuteEvents.Execute<IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
}
pointerEvent.dragging = false;
pointerEvent.pointerDrag = null;
if (pointerEvent.pointerDrag != null)
{
ExecuteEvents.Execute<IEndDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
}
pointerEvent.pointerDrag = null;
ExecuteEvents.ExecuteHierarchy<IPointerExitHandler>(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
pointerEvent.pointerEnter = null;
}
}
public override void DeactivateModule()
{
base.DeactivateModule();
base.ClearSelection();
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine((!this.UseFakeInput()) ? "Input: Touch" : "Input: Faked");
if (this.UseFakeInput())
{
PointerEventData lastPointerEventData = base.GetLastPointerEventData(-1);
if (lastPointerEventData != null)
{
stringBuilder.AppendLine(lastPointerEventData.ToString());
}
}
else
{
foreach (KeyValuePair<int, PointerEventData> current in this.m_PointerData)
{
stringBuilder.AppendLine(current.ToString());
}
}
return stringBuilder.ToString();
}
}
}