namespace UnityEngine.EventSystems { /// /// Base class that all EventSystem events inherit from. /// public interface IEventSystemHandler { } /// /// Interface to implement if you wish to receive OnPointerEnter callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IPointerEnterHandler : IEventSystemHandler { /// /// Use this callback to detect pointer enter events /// void OnPointerEnter(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnPointerExit callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IPointerExitHandler : IEventSystemHandler { /// /// Use this callback to detect pointer exit events /// void OnPointerExit(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnPointerDown callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IPointerDownHandler : IEventSystemHandler { /// /// Use this callback to detect pointer down events. /// void OnPointerDown(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnPointerUp callbacks. /// Note: In order to receive OnPointerUp callbacks, you must also implement the EventSystems.IPointerDownHandler|IPointerDownHandler interface /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IPointerUpHandler : IEventSystemHandler { /// /// Use this callback to detect pointer up events. /// void OnPointerUp(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnPointerClick callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// /// /// Use the IPointerClickHandler Interface to handle click input using OnPointerClick callbacks. Ensure an Event System exists in the Scene to allow click detection. For click detection on non-UI GameObjects, ensure a EventSystems.PhysicsRaycaster is attached to the Camera. /// /// /// /// using UnityEngine; /// using UnityEngine.EventSystems; /// /// public class Example : MonoBehaviour, IPointerClickHandler /// { /// //Detect if a click occurs /// public void OnPointerClick(PointerEventData pointerEventData) /// { /// //Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject. /// Debug.Log(name + " Game Object Clicked!"); /// } /// } /// /// public interface IPointerClickHandler : IEventSystemHandler { /// /// Use this callback to detect clicks. /// void OnPointerClick(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnBeginDrag callbacks. /// Note: You need to implement IDragHandler in addition to IBeginDragHandler. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IBeginDragHandler : IEventSystemHandler { /// /// Called by a BaseInputModule before a drag is started. /// void OnBeginDrag(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnInitializePotentialDrag callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IInitializePotentialDragHandler : IEventSystemHandler { /// /// Called by a BaseInputModule when a drag has been found but before it is valid to begin the drag. /// void OnInitializePotentialDrag(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnDrag callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// /// /// /// using UnityEngine; /// using UnityEngine.EventSystems; /// using UnityEngine.UI; /// /// [RequireComponent(typeof(Image))] /// public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler /// { /// public bool dragOnSurfaces = true; /// /// private GameObject m_DraggingIcon; /// private RectTransform m_DraggingPlane; /// /// public void OnBeginDrag(PointerEventData eventData) /// { /// var canvas = FindInParents(gameObject); /// if (canvas == null) /// return; /// /// // We have clicked something that can be dragged. /// // What we want to do is create an icon for this. /// m_DraggingIcon = new GameObject("icon"); /// /// m_DraggingIcon.transform.SetParent(canvas.transform, false); /// m_DraggingIcon.transform.SetAsLastSibling(); /// /// var image = m_DraggingIcon.AddComponent(); /// /// image.sprite = GetComponent().sprite; /// image.SetNativeSize(); /// /// if (dragOnSurfaces) /// m_DraggingPlane = transform as RectTransform; /// else /// m_DraggingPlane = canvas.transform as RectTransform; /// /// SetDraggedPosition(eventData); /// } /// /// public void OnDrag(PointerEventData data) /// { /// if (m_DraggingIcon != null) /// SetDraggedPosition(data); /// } /// /// private void SetDraggedPosition(PointerEventData data) /// { /// if (dragOnSurfaces && data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null) /// m_DraggingPlane = data.pointerEnter.transform as RectTransform; /// /// var rt = m_DraggingIcon.GetComponent(); /// Vector3 globalMousePos; /// if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlane, data.position, data.pressEventCamera, out globalMousePos)) /// { /// rt.position = globalMousePos; /// rt.rotation = m_DraggingPlane.rotation; /// } /// } /// /// public void OnEndDrag(PointerEventData eventData) /// { /// if (m_DraggingIcon != null) /// Destroy(m_DraggingIcon); /// } /// /// static public T FindInParents(GameObject go) where T : Component /// { /// if (go == null) return null; /// var comp = go.GetComponent(); /// /// if (comp != null) /// return comp; /// /// Transform t = go.transform.parent; /// while (t != null && comp == null) /// { /// comp = t.gameObject.GetComponent(); /// t = t.parent; /// } /// return comp; /// } /// } /// /// public interface IDragHandler : IEventSystemHandler { /// /// When dragging is occurring this will be called every time the cursor is moved. /// void OnDrag(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnEndDrag callbacks. /// Note: You need to implement IDragHandler in addition to IEndDragHandler. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IEndDragHandler : IEventSystemHandler { /// /// Called by a BaseInputModule when a drag is ended. /// void OnEndDrag(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnDrop callbacks. /// /// /// /// using UnityEngine; /// using UnityEngine.EventSystems; /// /// public class DropMe : MonoBehaviour, IDropHandler /// { /// public void OnDrop(PointerEventData data) /// { /// if (data.pointerDrag != null) /// { /// Debug.Log ("Dropped object was: " + data.pointerDrag); /// } /// } /// } /// /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IDropHandler : IEventSystemHandler { /// /// Called by a BaseInputModule on a target that can accept a drop. /// void OnDrop(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnScroll callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IScrollHandler : IEventSystemHandler { /// /// Use this callback to detect scroll events. /// void OnScroll(PointerEventData eventData); } /// /// Interface to implement if you wish to receive OnUpdateSelected callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IUpdateSelectedHandler : IEventSystemHandler { /// /// Called by the EventSystem when the object associated with this EventTrigger is updated. /// /// /// /// using UnityEngine; /// using UnityEngine.EventSystems; /// /// public class UpdateSelectedExample : MonoBehaviour, IUpdateSelectedHandler /// { /// public void OnUpdateSelected(BaseEventData data) /// { /// Debug.Log("OnUpdateSelected called."); /// } /// } /// /// void OnUpdateSelected(BaseEventData eventData); } /// /// Interface to implement if you wish to receive OnSelect callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface ISelectHandler : IEventSystemHandler { void OnSelect(BaseEventData eventData); } /// /// Interface to implement if you wish to receive OnDeselect callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IDeselectHandler : IEventSystemHandler { /// /// Called by the EventSystem when a new object is being selected. /// void OnDeselect(BaseEventData eventData); } /// /// Interface to implement if you wish to receive OnMove callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface IMoveHandler : IEventSystemHandler { /// /// Called by a BaseInputModule when a move event occurs. /// void OnMove(AxisEventData eventData); } /// /// Interface to implement if you wish to receive OnSubmit callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface ISubmitHandler : IEventSystemHandler { void OnSubmit(BaseEventData eventData); } /// /// Interface to implement if you wish to receive OnCancel callbacks. /// /// /// Criteria for this event is implementation dependent. For example see StandAloneInputModule. /// public interface ICancelHandler : IEventSystemHandler { void OnCancel(BaseEventData eventData); } }