A game about forced loneliness, made by TACStudios
1using System;
2using System.Text;
3using System.Collections.Generic;
4
5namespace UnityEngine.EventSystems
6{
7 /// <summary>
8 /// Each touch event creates one of these containing all the relevant information.
9 /// </summary>
10 public class PointerEventData : BaseEventData
11 {
12 /// <summary>
13 /// Input press tracking.
14 /// </summary>
15 public enum InputButton
16 {
17 /// <summary>
18 /// Left button
19 /// </summary>
20 Left = 0,
21
22 /// <summary>
23 /// Right button.
24 /// </summary>
25 Right = 1,
26
27 /// <summary>
28 /// Middle button
29 /// </summary>
30 Middle = 2
31 }
32
33 /// <summary>
34 /// The state of a press for the given frame.
35 /// </summary>
36 public enum FramePressState
37 {
38 /// <summary>
39 /// Button was pressed this frame.
40 /// </summary>
41 Pressed,
42
43 /// <summary>
44 /// Button was released this frame.
45 /// </summary>
46 Released,
47
48 /// <summary>
49 /// Button was pressed and released this frame.
50 /// </summary>
51 PressedAndReleased,
52
53 /// <summary>
54 /// Same as last frame.
55 /// </summary>
56 NotChanged
57 }
58
59 /// <summary>
60 /// The object that received 'OnPointerEnter'.
61 /// </summary>
62 public GameObject pointerEnter { get; set; }
63
64 // The object that received OnPointerDown
65 private GameObject m_PointerPress;
66
67 /// <summary>
68 /// The raw GameObject for the last press event. This means that it is the 'pressed' GameObject even if it can not receive the press event itself.
69 /// </summary>
70 public GameObject lastPress { get; private set; }
71
72 /// <summary>
73 /// The object that the press happened on even if it can not handle the press event.
74 /// </summary>
75 public GameObject rawPointerPress { get; set; }
76
77 /// <summary>
78 /// The object that is receiving 'OnDrag'.
79 /// </summary>
80 public GameObject pointerDrag { get; set; }
81
82 /// <summary>
83 /// The object that should receive the 'OnPointerClick' event.
84 /// </summary>
85 public GameObject pointerClick { get; set; }
86
87 /// <summary>
88 /// RaycastResult associated with the current event.
89 /// </summary>
90 public RaycastResult pointerCurrentRaycast { get; set; }
91
92 /// <summary>
93 /// RaycastResult associated with the pointer press.
94 /// </summary>
95 public RaycastResult pointerPressRaycast { get; set; }
96
97 public List<GameObject> hovered = new List<GameObject>();
98
99 /// <summary>
100 /// Is it possible to click this frame
101 /// </summary>
102 public bool eligibleForClick { get; set; }
103
104 /// <summary>
105 /// The index of the display that this pointer event comes from.
106 /// </summary>
107 public int displayIndex { get; set; }
108
109 /// <summary>
110 /// Id of the pointer (touch id).
111 /// </summary>
112 public int pointerId { get; set; }
113
114 /// <summary>
115 /// Current pointer position.
116 /// </summary>
117 public Vector2 position { get; set; }
118
119 /// <summary>
120 /// Pointer delta since last update.
121 /// </summary>
122 public Vector2 delta { get; set; }
123
124 /// <summary>
125 /// Position of the press.
126 /// </summary>
127 public Vector2 pressPosition { get; set; }
128
129 /// <summary>
130 /// World-space position where a ray cast into the screen hits something
131 /// </summary>
132
133 [Obsolete("Use either pointerCurrentRaycast.worldPosition or pointerPressRaycast.worldPosition")]
134 public Vector3 worldPosition { get; set; }
135
136 /// <summary>
137 /// World-space normal where a ray cast into the screen hits something
138 /// </summary>
139 [Obsolete("Use either pointerCurrentRaycast.worldNormal or pointerPressRaycast.worldNormal")]
140 public Vector3 worldNormal { get; set; }
141
142 /// <summary>
143 /// The last time a click event was sent. Used for double click
144 /// </summary>
145 public float clickTime { get; set; }
146
147 /// <summary>
148 /// Number of clicks in a row.
149 /// </summary>
150 /// <example>
151 /// <code>
152 /// <![CDATA[
153 /// using UnityEngine;
154 /// using System.Collections;
155 /// using UnityEngine.UI;
156 /// using UnityEngine.EventSystems;// Required when using Event data.
157 ///
158 /// public class ExampleClass : MonoBehaviour, IPointerDownHandler
159 /// {
160 /// public void OnPointerDown(PointerEventData eventData)
161 /// {
162 /// //Grab the number of consecutive clicks and assign it to an integer varible.
163 /// int i = eventData.clickCount;
164 /// //Display the click count.
165 /// Debug.Log(i);
166 /// }
167 /// }
168 /// ]]>
169 ///</code>
170 /// </example>
171 public int clickCount { get; set; }
172
173 /// <summary>
174 /// The amount of scroll since the last update.
175 /// </summary>
176 public Vector2 scrollDelta { get; set; }
177
178 /// <summary>
179 /// Should a drag threshold be used?
180 /// </summary>
181 /// <remarks>
182 /// If you do not want a drag threshold set this to false in IInitializePotentialDragHandler.OnInitializePotentialDrag.
183 /// </remarks>
184 public bool useDragThreshold { get; set; }
185
186 /// <summary>
187 /// Is a drag operation currently occuring.
188 /// </summary>
189 public bool dragging { get; set; }
190
191 /// <summary>
192 /// The EventSystems.PointerEventData.InputButton for this event.
193 /// </summary>
194 public InputButton button { get; set; }
195
196
197 /// <summary>
198 /// The amount of pressure currently applied by a touch.
199 /// </summary>
200 /// <remarks>
201 /// If the device does not report pressure, the value of this property is 1.0f.
202 /// </remarks>
203 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
204 public float pressure { get; set; }
205 /// <summary>
206 /// The pressure applied to an additional pressure-sensitive control on the stylus.
207 /// </summary>
208 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
209 public float tangentialPressure { get; set; }
210 /// <summary>
211 /// The angle of the stylus relative to the surface, in radians
212 /// </summary>
213 /// <remarks>
214 /// A value of 0 indicates that the stylus is parallel to the surface. A value of pi/2 indicates that it is perpendicular to the surface.
215 /// </remarks>
216 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
217 public float altitudeAngle { get; set; }
218 /// <summary>
219 /// The angle of the stylus relative to the x-axis, in radians.
220 /// </summary>
221 /// <remarks>
222 /// A value of 0 indicates that the stylus is pointed along the x-axis of the device.
223 /// </remarks>
224 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
225 public float azimuthAngle { get; set; }
226 /// <summary>
227 /// The rotation of the stylus around its axis, in radians.
228 /// </summary>
229 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
230 public float twist { get; set; }
231 /// <summary>
232 /// Specifies the angle of the pen relative to the X & Y axis, in radians.
233 /// </summary>
234 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
235 public Vector2 tilt { get; set; }
236 /// <summary>
237 /// Specifies the state of the pen. For example, whether the pen is in contact with the screen or tablet, whether the pen is inverted, and whether buttons are pressed.
238 /// </summary>
239 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
240 public PenStatus penStatus { get; set; }
241 /// <summary>
242 /// An estimate of the radius of a touch.
243 /// </summary>
244 /// <remarks>
245 /// Add `radiusVariance` to get the maximum touch radius, subtract it to get the minimum touch radius.
246 /// </remarks>
247 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
248 public Vector2 radius { get; set; }
249 /// <summary>
250 /// The accuracy of the touch radius.
251 /// </summary>
252 /// <remarks>
253 /// Add this value to the radius to get the maximum touch radius, subtract it to get the minimum touch radius.
254 /// </remarks>
255 public Vector2 radiusVariance { get; set; }
256 /// <summary>
257 /// Specifies in the case of a pointer exit if the pointer has fully exited the area or if it has just entered a child.
258 /// </summary>
259 public bool fullyExited { get; set; }
260 /// <summary>
261 /// Specifies in the case of a pointer enter if the pointer has entered a new area or if it has just reentered a parent after leaving a child.
262 /// </summary>
263 public bool reentered { get; set; }
264 /// <seealso cref="UnityEngine.UIElements.IPointerEvent" />
265
266 public PointerEventData(EventSystem eventSystem) : base(eventSystem)
267 {
268 eligibleForClick = false;
269
270 displayIndex = 0;
271 pointerId = -1;
272 position = Vector2.zero; // Current position of the mouse or touch event
273 delta = Vector2.zero; // Delta since last update
274 pressPosition = Vector2.zero; // Delta since the event started being tracked
275 clickTime = 0.0f; // The last time a click event was sent out (used for double-clicks)
276 clickCount = 0; // Number of clicks in a row. 2 for a double-click for example.
277
278 scrollDelta = Vector2.zero;
279 useDragThreshold = true;
280 dragging = false;
281 button = InputButton.Left;
282
283 pressure = 0f;
284 tangentialPressure = 0f;
285 altitudeAngle = 0f;
286 azimuthAngle = 0f;
287 twist = 0f;
288 tilt = new Vector2(0f, 0f);
289 penStatus = PenStatus.None;
290 radius = Vector2.zero;
291 radiusVariance = Vector2.zero;
292 }
293
294 /// <summary>
295 /// Is the pointer moving.
296 /// </summary>
297 public bool IsPointerMoving()
298 {
299 return delta.sqrMagnitude > 0.0f;
300 }
301
302 /// <summary>
303 /// Is scroll being used on the input device.
304 /// </summary>
305 public bool IsScrolling()
306 {
307 return scrollDelta.sqrMagnitude > 0.0f;
308 }
309
310 /// <summary>
311 /// The camera associated with the last OnPointerEnter event.
312 /// </summary>
313 public Camera enterEventCamera
314 {
315 get { return pointerCurrentRaycast.module == null ? null : pointerCurrentRaycast.module.eventCamera; }
316 }
317
318 /// <summary>
319 /// The camera associated with the last OnPointerPress event.
320 /// </summary>
321 public Camera pressEventCamera
322 {
323 get { return pointerPressRaycast.module == null ? null : pointerPressRaycast.module.eventCamera; }
324 }
325
326 /// <summary>
327 /// The GameObject that received the OnPointerDown.
328 /// </summary>
329 public GameObject pointerPress
330 {
331 get { return m_PointerPress; }
332 set
333 {
334 if (m_PointerPress == value)
335 return;
336
337 lastPress = m_PointerPress;
338 m_PointerPress = value;
339 }
340 }
341
342 public override string ToString()
343 {
344 var sb = new StringBuilder();
345 sb.AppendLine("<b>Position</b>: " + position);
346 sb.AppendLine("<b>delta</b>: " + delta);
347 sb.AppendLine("<b>eligibleForClick</b>: " + eligibleForClick);
348 sb.AppendLine("<b>pointerEnter</b>: " + pointerEnter);
349 sb.AppendLine("<b>pointerPress</b>: " + pointerPress);
350 sb.AppendLine("<b>lastPointerPress</b>: " + lastPress);
351 sb.AppendLine("<b>pointerDrag</b>: " + pointerDrag);
352 sb.AppendLine("<b>Use Drag Threshold</b>: " + useDragThreshold);
353 sb.AppendLine("<b>Current Raycast:</b>");
354 sb.AppendLine(pointerCurrentRaycast.ToString());
355 sb.AppendLine("<b>Press Raycast:</b>");
356 sb.AppendLine(pointerPressRaycast.ToString());
357 sb.AppendLine("<b>Display Index:</b>");
358 sb.AppendLine(displayIndex.ToString());
359 sb.AppendLine("<b>pressure</b>: " + pressure);
360 sb.AppendLine("<b>tangentialPressure</b>: " + tangentialPressure);
361 sb.AppendLine("<b>altitudeAngle</b>: " + altitudeAngle);
362 sb.AppendLine("<b>azimuthAngle</b>: " + azimuthAngle);
363 sb.AppendLine("<b>twist</b>: " + twist);
364 sb.AppendLine("<b>tilt</b>: " + tilt);
365 sb.AppendLine("<b>penStatus</b>: " + penStatus);
366 sb.AppendLine("<b>radius</b>: " + radius);
367 sb.AppendLine("<b>radiusVariance</b>: " + radiusVariance);
368 return sb.ToString();
369 }
370 }
371}