--创建一个只响应点击事件不渲染的节点(GameObject)
using UnityEngine;
using System.Collections;
namespace UnityEngine.UI
{
public class Empty4Raycast : MaskableGraphic
{
protected Empty4Raycast()
{
useLegacyMeshGeneration = false;
}
protected override void OnPopulateMesh(VertexHelper toFill)
{
toFill.Clear();
}
}
}
--
public override void OnPointerClick(PointerEventData eventData)
{
if(onPointerClickEvent != null)
{
onPointerClickEvent(this.gameObject, eventData);
}
if (isPassEvent)
{
PassEvent(eventData, ExecuteEvents.pointerClickHandler);
}
}
//把事件透下去
public void PassEvent(PointerEventData data, ExecuteEvents.EventFunction func)
where T : IEventSystemHandler
{
List results = new List();
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, func);
}
}
}