Unity的UnityEngine.EventSystems中的接口

一、
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, IEndDragHandler

复制代码
public void OnBeginDrag(PointerEventData eventData)
    {
        Debug.Log("OnBeginDrag,鼠标拖动动作开始的瞬间执行一次");
    }

    public void OnDrag(PointerEventData eventData)
    {
        Debug.Log("OnDrag,鼠标拖动过程中每帧调用");
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        Debug.Log("OnEndDrag,鼠标拖动动作松开的时候调用一次");
    }
复制代码

三、

IsPointerOverGameObject

复制代码
public 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;
        }
复制代码

 

posted @   weigang  阅读(121)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示