private PointerEventData _uiPointerEventData;
private List _uiRaycastResultCache = new List();
public bool IsTouchAnyUI(Vector2 screenPos)
{
if (null == EventSystem.current)
return false;
if (_uiPointerEventData == null)
_uiPointerEventData = new PointerEventData(EventSystem.current);
_uiPointerEventData.position = new Vector2(screenPos.x, screenPos.y);
EventSystem.current.RaycastAll(_uiPointerEventData, _uiRaycastResultCache);
return _uiRaycastResultCache.Count > 0;
}
public bool IsTouchUI(Vector2 screenPos, GameObject uiGo)
{
if (null == EventSystem.current)
return false;
if (_uiPointerEventData == null)
_uiPointerEventData = new PointerEventData(EventSystem.current);
_uiPointerEventData.position = new Vector2(screenPos.x, screenPos.y);
EventSystem.current.RaycastAll(_uiPointerEventData, _uiRaycastResultCache);
for (int i = 0; i < _uiRaycastResultCache.Count; i++)
{
if (_uiRaycastResultCache[i].gameObject == uiGo)
return true;
}
return false;
}
Original: https://www.cnblogs.com/sailJs/p/16447592.html
Author: yanghui01
Title: 使用EventSystem判断是否点击ui
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/583498/
转载文章受原作者版权保护。转载请注明原作者出处!