using System; using System.Text; using System.Collections.Generic; namespace UnityEngine.EventSystems { /// /// Each touch event creates one of these containing all the relevant information. /// public class PointerEventData : BaseEventData { /// /// Input press tracking. /// public enum InputButton { /// /// Left button /// Left = 0, /// /// Right button. /// Right = 1, /// /// Middle button /// Middle = 2 } /// /// The state of a press for the given frame. /// public enum FramePressState { /// /// Button was pressed this frame. /// Pressed, /// /// Button was released this frame. /// Released, /// /// Button was pressed and released this frame. /// PressedAndReleased, /// /// Same as last frame. /// NotChanged } /// /// The object that received 'OnPointerEnter'. /// public GameObject pointerEnter { get; set; } // The object that received OnPointerDown private GameObject m_PointerPress; /// /// 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. /// public GameObject lastPress { get; private set; } /// /// The object that the press happened on even if it can not handle the press event. /// public GameObject rawPointerPress { get; set; } /// /// The object that is receiving 'OnDrag'. /// public GameObject pointerDrag { get; set; } /// /// The object that should receive the 'OnPointerClick' event. /// public GameObject pointerClick { get; set; } /// /// RaycastResult associated with the current event. /// public RaycastResult pointerCurrentRaycast { get; set; } /// /// RaycastResult associated with the pointer press. /// public RaycastResult pointerPressRaycast { get; set; } public List hovered = new List(); /// /// Is it possible to click this frame /// public bool eligibleForClick { get; set; } /// /// Id of the pointer (touch id). /// public int pointerId { get; set; } /// /// Current pointer position. /// public Vector2 position { get; set; } /// /// Pointer delta since last update. /// public Vector2 delta { get; set; } /// /// Position of the press. /// public Vector2 pressPosition { get; set; } /// /// World-space position where a ray cast into the screen hits something /// [Obsolete("Use either pointerCurrentRaycast.worldPosition or pointerPressRaycast.worldPosition")] public Vector3 worldPosition { get; set; } /// /// World-space normal where a ray cast into the screen hits something /// [Obsolete("Use either pointerCurrentRaycast.worldNormal or pointerPressRaycast.worldNormal")] public Vector3 worldNormal { get; set; } /// /// The last time a click event was sent. Used for double click /// public float clickTime { get; set; } /// /// Number of clicks in a row. /// /// /// /// /// /// public int clickCount { get; set; } /// /// The amount of scroll since the last update. /// public Vector2 scrollDelta { get; set; } /// /// Should a drag threshold be used? /// /// /// If you do not want a drag threshold set this to false in IInitializePotentialDragHandler.OnInitializePotentialDrag. /// public bool useDragThreshold { get; set; } /// /// Is a drag operation currently occuring. /// public bool dragging { get; set; } /// /// The EventSystems.PointerEventData.InputButton for this event. /// public InputButton button { get; set; } /// /// The amount of pressure currently applied by a touch. /// /// /// If the device does not report pressure, the value of this property is 1.0f. /// /// public float pressure { get; set; } /// /// The pressure applied to an additional pressure-sensitive control on the stylus. /// /// public float tangentialPressure { get; set; } /// /// The angle of the stylus relative to the surface, in radians /// /// /// 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. /// /// public float altitudeAngle { get; set; } /// /// The angle of the stylus relative to the x-axis, in radians. /// /// /// A value of 0 indicates that the stylus is pointed along the x-axis of the device. /// /// public float azimuthAngle { get; set; } /// /// The rotation of the stylus around its axis, in radians. /// /// public float twist { get; set; } /// /// An estimate of the radius of a touch. /// /// /// Add `radiusVariance` to get the maximum touch radius, subtract it to get the minimum touch radius. /// /// public Vector2 radius { get; set; } /// /// The accuracy of the touch radius. /// /// /// Add this value to the radius to get the maximum touch radius, subtract it to get the minimum touch radius. /// public Vector2 radiusVariance { get; set; } /// public PointerEventData(EventSystem eventSystem) : base(eventSystem) { eligibleForClick = false; pointerId = -1; position = Vector2.zero; // Current position of the mouse or touch event delta = Vector2.zero; // Delta since last update pressPosition = Vector2.zero; // Delta since the event started being tracked clickTime = 0.0f; // The last time a click event was sent out (used for double-clicks) clickCount = 0; // Number of clicks in a row. 2 for a double-click for example. scrollDelta = Vector2.zero; useDragThreshold = true; dragging = false; button = InputButton.Left; pressure = 0f; tangentialPressure = 0f; altitudeAngle = 0f; azimuthAngle = 0f; twist = 0f; radius = Vector2.zero; radiusVariance = Vector2.zero; } /// /// Is the pointer moving. /// public bool IsPointerMoving() { return delta.sqrMagnitude > 0.0f; } /// /// Is scroll being used on the input device. /// public bool IsScrolling() { return scrollDelta.sqrMagnitude > 0.0f; } /// /// The camera associated with the last OnPointerEnter event. /// public Camera enterEventCamera { get { return pointerCurrentRaycast.module == null ? null : pointerCurrentRaycast.module.eventCamera; } } /// /// The camera associated with the last OnPointerPress event. /// public Camera pressEventCamera { get { return pointerPressRaycast.module == null ? null : pointerPressRaycast.module.eventCamera; } } /// /// The GameObject that received the OnPointerDown. /// public GameObject pointerPress { get { return m_PointerPress; } set { if (m_PointerPress == value) return; lastPress = m_PointerPress; m_PointerPress = value; } } public override string ToString() { var sb = new StringBuilder(); sb.AppendLine("Position: " + position); sb.AppendLine("delta: " + delta); sb.AppendLine("eligibleForClick: " + eligibleForClick); sb.AppendLine("pointerEnter: " + pointerEnter); sb.AppendLine("pointerPress: " + pointerPress); sb.AppendLine("lastPointerPress: " + lastPress); sb.AppendLine("pointerDrag: " + pointerDrag); sb.AppendLine("Use Drag Threshold: " + useDragThreshold); sb.AppendLine("Current Raycast:"); sb.AppendLine(pointerCurrentRaycast.ToString()); sb.AppendLine("Press Raycast:"); sb.AppendLine(pointerPressRaycast.ToString()); sb.AppendLine("pressure: " + pressure); sb.AppendLine("tangentialPressure: " + tangentialPressure); sb.AppendLine("altitudeAngle: " + altitudeAngle); sb.AppendLine("azimuthAngle: " + azimuthAngle); sb.AppendLine("twist: " + twist); sb.AppendLine("radius: " + radius); sb.AppendLine("radiusVariance: " + radiusVariance); return sb.ToString(); } } }