第一种
/// <summary>
/// 检测当前点击的是UI
/// </summary>
/// <returns></returns>
private bool IsActionOnUI()
{
#if IPHONE || ANDROID
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
if (EventSystem.current.IsPointerOverGameObject() && EventSystem.current.currentSelectedGameObject != null)
{
#endif
return true;
}
else
{
return false;
}
}
第二种
bool CheckGuiRaycastObjects()
{
PointerEventData eventData = new PointerEventData(Main.Instance.eventSystem);
eventData.pressPosition = Input.mousePosition;
eventData.position = Input.mousePosition;
List<RaycastResult> list = new List<RaycastResult>();
Main.Instance.graphicRaycaster.Raycast(eventData, list);
//Debug.Log(list.Count);
return list.Count > 0;
/// 检测当前点击的是UI
/// </summary>
/// <returns></returns>
private bool IsActionOnUI()
{
#if IPHONE || ANDROID
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
if (EventSystem.current.IsPointerOverGameObject() && EventSystem.current.currentSelectedGameObject != null)
{
#endif
return true;
}
else
{
return false;
}
}
第二种
{
PointerEventData eventData = new PointerEventData(Main.Instance.eventSystem);
eventData.pressPosition = Input.mousePosition;
eventData.position = Input.mousePosition;
List<RaycastResult> list = new List<RaycastResult>();
Main.Instance.graphicRaycaster.Raycast(eventData, list);
//Debug.Log(list.Count);
return list.Count > 0;
}
只是知道有这两种方式,并不会比较两者的区别,有大神可以帮忙分析一下。