一、 IPointerDownHandler,IPointerUpHandler,IPointerClickHandler,IPointerEnterHandler,IPointerExitHandler
public void OnPointerClick(PointerEventData eventData) { Debug.Log("OnPointerClick,鼠标点击,在点击之后抬起时响应"); } public void OnPointerDown(PointerEventData eventData) { Debug.Log("OnPointerDown,鼠标在UI上按下时候响应"); } public void OnPointerUp(PointerEventData eventData) { Debug.Log("OnPointerUp,鼠标在UI上抬起时候响应"); } public void OnPointerEnter(PointerEventData eventData) { Debug.Log("OnPointerEnter,鼠标光标进入UI范围瞬间响应"); } public void OnPointerExit(PointerEventData eventData) { Debug.Log("OnPointerExit,鼠标光标离开UI范围瞬间响应"); }
二、
IBeginDragHandler, IDragHandler, IEndDragHandlerpublic void OnBeginDrag(PointerEventData eventData) { Debug.Log("OnBeginDrag,鼠标拖动动作开始的瞬间执行一次"); } public void OnDrag(PointerEventData eventData) { Debug.Log("OnDrag,鼠标拖动过程中每帧调用"); } public void OnEndDrag(PointerEventData eventData) { Debug.Log("OnEndDrag,鼠标拖动动作松开的时候调用一次"); }
三、
IsPointerOverGameObjectpublic class EventSystemTest : MonoBehaviour { void Update() { if (EventSystem.current.IsPointerOverGameObject()) { Debug.Log("鼠标光标处在UI上方每帧调用"); } } }
四、
鼠标点击处,屏幕上一点的UI层数 EventSystem.current.RaycastAll()//点击区域碰撞数 public static bool IsPointerOverUIObject(Vector2 screenPosition) { PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current); eventDataCurrentPosition.position = screenPosition; List<RaycastResult> results = new List<RaycastResult>(); EventSystem.current.RaycastAll(eventDataCurrentPosition, results); return results.Count > 5; }
标签:UnityEngine,鼠标,void,PointerEventData,Unity,EventSystems,Debug,public,Log From: https://www.cnblogs.com/weigangblog/p/18204046