当想要UI和3D物体同时响应时,利用ExecuteEvents可以实现。
public void ExecuteAll(PointerEventData eventData)
{
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(eventData,results);
foreach (var result in results)
{
if (result.gameObject != this.gameObject)
{
ExecuteEvents.Execute(result.gameObject,eventData,ExecuteEvents.pointerClickHandler);
}
}
}