[Introduction] Interface
Namespace: using UnityEngine.EventSystems;
IPointerEnterHandler
This interface is implemented as follows:
void OnPointerEnter public (PointerEventData eventDataA) { // triggered when the mouse cursor into the subject }
IPointerExitHandler
This interface is implemented as follows:
void OnPointerExit public (PointerEventData eventDataA) { // triggered when the mouse cursor out of the subject }
IPointerDownHandler
This interface is implemented as follows:
void OnPointerDown public (PointerEventData eventDataA) { // A mouse click on the object, A target in response to this event, when the mouse }
IPointerUpHandler
This interface is implemented as follows:
void OnPointerUp public (PointerEventData eventData) { // A mouse click on the object, the response when you lift the mouse // regardless of where the mouse lifted (ie, not the object A) // will respond to this event in the A object // Note: provided that a in response to this event through the object must respond to events OnPointerDown Debug.Log ( "OnPointerUp" + name); }
IPointerClickHandler
This interface is implemented as follows:
void OnPointerClick public (PointerEventData eventDataA) { // A mouse click on the object, A in response to this event the object is lifted mouse // NOTE: When lifting the mouse to be pressed and at the same object }
IDragHandler
This interface is implemented as follows:
void ondrag public (PointerEventData eventDataA) { // when the mouse is pressed on the object A and the object A in response to this event once per frame when the dragging // NOTE: If you do not implement this interface, the four interfaces will not trigger the latter method Debug.Log ( "ondrag" + name); IF (Input.GetMouseButton (0)) { // drag moving pictures SetDraggedPosition (eventDataA); } } Private void SetDraggedPosition (PointerEventData eventDataA) { var gameObject.GetComponent RT = <RectTransform > (); Vector3 globalMousePos; IF (RectTransformUtility.ScreenPointToWorldPointInRectangle (RT, eventData.position, eventData.pressEventCamera, globalMousePos OUT)) { rt.position globalMousePos =; } }
IInitializePotentialDragHandler
This interface is implemented as follows:
void OnInitializePotentialDrag public (PointerEventData eventDataA) { // when the mouse is pressed when the object A has not yet begun drag objects respond to this event A // NOTE: This interface similar to interface events IPointerDownHandler event execution order of both @: first execution IPointerDownHandler, then execute the interface event Debug.Log ( "OnInitializePotentialDrag" + name); }
IBeginDragHandler
This interface is implemented as follows:
void OnBeginDrag public (PointerEventData eventDataA) { // when the mouse down and begins dragging the object A in response to this event object A // response before this event response OnDrag after OnInitializePotentialDrag Debug.Log ( "OnBeginDrag" + name); }
IEndDragHandler
This interface is implemented as follows:
void OnEndDrag public (PointerEventData eventDataA) { // when the mouse event in response to the object A is lifted Debug.Log ( "OnEndDrag" + name); }
IDropHandler
This interface is implemented as follows:
void OnDrop public (PointerEventData eventDataA) { // A, B object must have achieved IDropHandler interface A and an interface implemented at least IDragHandler @ A when the object starts from the mouse drag, the object B in response to this event when lifting the object B // At this time, the acquired name is the name attribute of the object B //eventData.pointerDrag represents initiated dragged objects (the GameObject) Debug.Log (eventData.pointerDrag.name + "OnDrop to" + name); }