版本号:2017.4.29f

判断是否点击\触摸在UI上所调用的 EventSystem.current.IsPointerOverGameObject() 接口有问题,在真机无法返回正确判断。

处理办法:
1、UI事件发出射线检测

    public static bool IsPointerOverGameObject()
    {
        PointerEventData eventData = new PointerEventData(UnityEngine.EventSystems.EventSystem.current);
        eventData.pressPosition = Input.mousePosition;
        eventData.position = Input.mousePosition;

        List<RaycastResult> list = new List<RaycastResult>();
        UnityEngine.EventSystems.EventSystem.current.RaycastAll(eventData, list);

        return list.Count > 0;
    }

2、Canvas的GraphicRaycaster发出射线检测


    public bool IsPointerOverGameObject(Canvas canvas)
    {
        PointerEventData eventData = new PointerEventData(EventSystem.current);
        eventData.pressPosition = Input.mousePosition;
        eventData.position = Input.mousePosition;

        GraphicRaycaster uiRaycaster = canvas.gameObject.GetComponent<GraphicRaycaster>();

        List<RaycastResult> results = new List<RaycastResult>();
        uiRaycaster.Raycast(eventData, results);

        return results.Count > 0;
    }
12-26 21:16