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.
///
///
///
/// using UnityEngine;
/// using System.Collections;
/// using UnityEngine.UI;
/// using UnityEngine.EventSystems;// Required when using Event data.
///
/// public class ExampleClass : MonoBehaviour, IPointerDownHandler
/// {
/// public void OnPointerDown(PointerEventData eventData)
/// {
/// //Grab the number of consecutive clicks and assign it to an integer varible.
/// int i = eventData.clickCount;
/// //Display the click count.
/// Debug.Log(i);
/// }
/// }
///
///
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; }
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;
}
///
/// 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());
return sb.ToString();
}
}
}