版本號:**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;
}
