using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Script_05_09 : MonoBehaviour, IPointerClickHandler,
IPointerDownHandler, IPointerUpHandler
{
//监听点击
public void OnPointerClick(PointerEventData eventData)
{
PassEvent(eventData, ExecuteEvents.submitHandler);
PassEvent(eventData, ExecuteEvents.pointerClickHandler);
}
//监听按下
public void OnPointerDown(PointerEventData eventData)
{
PassEvent(eventData, ExecuteEvents.pointerDownHandler);
}
//监听抬起
public void OnPointerUp(PointerEventData eventData)
{
PassEvent(eventData, ExecuteEvents.pointerUpHandler);
}
public void PassEvent<T>(PointerEventData data,ExecuteEvents.EventFunction<T> function)
where T:IEventSystemHandler
{
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(data, results);
GameObject current = data.pointerCurrentRaycast.gameObject;
for(int i=0;i<results.Count;i++)
{
if(current!=results[i].gameObject)
{
ExecuteEvents.Execute(results[i].gameObject, data, function);
//如果只想渗透到下一层,只需break即可
//break;
}
}
}
}