ExtendedPointerEventData.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI
  2. using System.Text;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.InputSystem.Controls;
  5. namespace UnityEngine.InputSystem.UI
  6. {
  7. /// <summary>
  8. /// An extension to <c>PointerEventData</c> which makes additional data about the input event available.
  9. /// </summary>
  10. /// <remarks>
  11. /// Instances of this class are sent instead of <see cref="PointerEventData"/> by <see cref="InputSystemUIInputModule"/>
  12. /// for all pointer-type input.
  13. ///
  14. /// The <see cref="PointerEventData.pointerId"/> property will generally correspond to the <see cref="InputDevice.deviceId"/>
  15. /// of <see cref="device"/>. An exception to this are touches as each <see cref="Touchscreen"/> may generate several pointers
  16. /// (one for each active finger).
  17. /// </remarks>
  18. public class ExtendedPointerEventData : PointerEventData
  19. {
  20. public ExtendedPointerEventData(EventSystem eventSystem)
  21. : base(eventSystem)
  22. {
  23. }
  24. /// <summary>
  25. /// The <see cref="InputDevice"/> that generated the pointer input.
  26. /// </summary>
  27. /// <seealso cref="Pointer"/>
  28. /// <seealso cref="Touchscreen"/>
  29. /// <seealso cref="Mouse"/>
  30. /// <seealso cref="Pen"/>
  31. public InputDevice device { get; set; }
  32. /// <summary>
  33. /// For <see cref="UIPointerType.Touch"/> type pointer input, this is the touch ID as reported by the
  34. /// <see cref="Touchscreen"/> device.
  35. /// </summary>
  36. /// <remarks>
  37. /// For pointer input that is not coming from touch, this will be 0 (which is not considered a valid touch ID
  38. /// by the input system).
  39. ///
  40. /// Note that for touch input, <see cref="PointerEventData.pointerId"/> will be a combination of the
  41. /// device ID of <see cref="device"/> and the touch ID to generate a unique pointer ID even if there
  42. /// are multiple touchscreens.
  43. /// </remarks>
  44. /// <seealso cref="TouchControl.touchId"/>
  45. public int touchId { get; set; }
  46. /// <summary>
  47. /// Type of pointer that generated the input.
  48. /// </summary>
  49. public UIPointerType pointerType { get; set; }
  50. /// <summary>
  51. /// For <see cref="UIPointerType.Tracked"/> type pointer input, this is the world-space position of
  52. /// the <see cref="TrackedDevice"/>.
  53. /// </summary>
  54. /// <seealso cref="InputSystemUIInputModule.trackedDevicePosition"/>
  55. public Vector3 trackedDevicePosition { get; set; }
  56. /// <summary>
  57. /// For <see cref="UIPointerType.Tracked"/> type pointer input, this is the world-space orientation of
  58. /// the <see cref="TrackedDevice"/>.
  59. /// </summary>
  60. /// <seealso cref="InputSystemUIInputModule.trackedDeviceOrientation"/>
  61. public Quaternion trackedDeviceOrientation { get; set; }
  62. public override string ToString()
  63. {
  64. var stringBuilder = new StringBuilder();
  65. stringBuilder.Append(base.ToString());
  66. stringBuilder.AppendLine("<b>device</b>: " + device);
  67. stringBuilder.AppendLine("<b>pointerType</b>: " + pointerType);
  68. stringBuilder.AppendLine("<b>touchId</b>: " + touchId);
  69. stringBuilder.AppendLine("<b>trackedDevicePosition</b>: " + trackedDevicePosition);
  70. stringBuilder.AppendLine("<b>trackedDeviceOrientation</b>: " + trackedDeviceOrientation);
  71. return stringBuilder.ToString();
  72. }
  73. internal static int MakePointerIdForTouch(int deviceId, int touchId)
  74. {
  75. unchecked
  76. {
  77. return (deviceId << 24) + touchId;
  78. }
  79. }
  80. ////TODO: adder pressure and tile support (probably add after 1.0; probably should have separate actions)
  81. /*
  82. /// <summary>
  83. /// If supported by the input device, this is the pressure level of the pointer contact. This is generally
  84. /// only supported by <see cref="Pen"/> devices as well as by <see cref="Touchscreen"/>s on phones. If not
  85. /// supported, this will be 1.
  86. /// </summary>
  87. /// <seealso cref="Pointer.pressure"/>
  88. public float pressure { get; set; }
  89. /// <summary>
  90. /// If the pointer input is coming from a <see cref="Pen"/>, this is pen's <see cref="Pen.tilt"/>.
  91. /// </summary>
  92. public Vector2 tilt { get; set; }
  93. */
  94. }
  95. /// <summary>
  96. /// General type of pointer that generated a <see cref="PointerEventData"/> pointer event.
  97. /// </summary>
  98. public enum UIPointerType
  99. {
  100. None,
  101. /// <summary>
  102. /// A <see cref="Mouse"/> or <see cref="Pen"/> or other general <see cref="Pointer"/>.
  103. /// </summary>
  104. MouseOrPen,
  105. /// <summary>
  106. /// A <see cref="Touchscreen"/>.
  107. /// </summary>
  108. Touch,
  109. /// <summary>
  110. /// A <see cref="TrackedDevice"/>.
  111. /// </summary>
  112. Tracked,
  113. }
  114. /// <summary>
  115. /// Determine how the UI behaves in the presence of multiple pointer devices.
  116. /// </summary>
  117. /// <remarks>
  118. /// While running, an application may, for example, have both a <see cref="Mouse"/> and a <see cref="Touchscreen"/> device
  119. /// and both may end up getting bound to the actions of <see cref="InputSystemUIInputModule"/> and thus both may route
  120. /// input into the UI. When this happens, the pointer behavior decides how the UI input module resolves the ambiguity.
  121. /// </remarks>
  122. public enum UIPointerBehavior
  123. {
  124. /// <summary>
  125. /// Any input that isn't <see cref="Touchscreen"/> or <see cref="TrackedDevice"/> input is
  126. /// treated as a single unified pointer.
  127. ///
  128. /// This is the default behavior based on the expectation that mice and pens will generally drive a single on-screen
  129. /// cursor whereas touch and tracked devices have an inherent ability to generate multiple pointers.
  130. ///
  131. /// Note that when input from touch or tracked devices is received, the combined pointer for mice and pens (if it exists)
  132. /// will be removed. If it was over UI objects, <c>IPointerExitHandler</c>s will be invoked.
  133. /// </summary>
  134. SingleMouseOrPenButMultiTouchAndTrack,
  135. /// <summary>
  136. /// All input is unified to a single pointer. This means that all input from all pointing devices (<see cref="Mouse"/>,
  137. /// <see cref="Pen"/>, <see cref="Touchscreen"/>, and <see cref="TrackedDevice"/>) is routed into a single pointer
  138. /// instance. There is only one position on screen which can be controlled from any of these devices.
  139. /// </summary>
  140. SingleUnifiedPointer,
  141. /// <summary>
  142. /// Any pointing device, whether it's <see cref="Mouse"/>, <see cref="Pen"/>, <see cref="Touchscreen"/>,
  143. /// or <see cref="TrackedDevice"/> input, is treated as its own independent pointer and arbitrary many
  144. /// such pointers can be active at any one time.
  145. /// </summary>
  146. AllPointersAsIs,
  147. }
  148. }
  149. #endif