public static bool IsPointerOverUIObject()
{
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE)
eventDataCurrentPosition.position = Input.GetTouch(0).position;
#else
eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
#endif
List<RaycastResult> results = new List<RaycastResult>();
if (EventSystem.current)
{
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
}
for (int i = 0; i < results.Count; i++)
{
if (results[i].gameObject.layer == LayerMask.NameToLayer("UI"))
return true;
}
return false;
}
网友评论