Version: 2017.3

ExecuteEvents.GetEventHandler

切换到手册
public static GameObject GetEventHandler (GameObject root);

参数

root GameObject

返回

GameObject 处理 GameObject

描述

遍历从 root 开始的对象层级视图,然后返回实现类型为 <T> 的事件处理程序的 GameObject

注意:遍历从根对象向上执行,而不是向下执行。

using UnityEngine;
using UnityEngine.EventSystems;

public class GetEventHandlerExample : MonoBehaviour { // Find the GameObject which implements IDragHandler

void Start() { GameObject handlerObject = ExecuteEvents.GetEventHandler<IDragHandler>(this.gameObject);

if (handlerObject == null) Debug.Log("Drag Handler not found."); else Debug.Log("Drag Handler is attached to GameObject '" + handlerObject.name + "'"); } }