1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| /// <summary> /// 点击 /// </summary> /// <param name="action"></param> /// <param name="MyObject"></param> public static void PointerClickEvent(Action action, GameObject MyObject) { // 定义所要绑定的事件类型 EventTrigger.Entry entry = new EventTrigger.Entry(); // 设置事件类型 entry.eventID = EventTriggerType.PointerClick; // 初始化回调函数 entry.callback = new EventTrigger.TriggerEvent(); // 定义回调函数 UnityEngine.Events.UnityAction<BaseEventData> callBack = new UnityEngine.Events.UnityAction<BaseEventData>(((BaseEventData baseEventData) => { action(); })); // 绑定回调函数 entry.callback.AddListener(callBack); //添加事件组件,添加方法 MyObject.AddComponent<EventTrigger>().triggers.Add(entry); }
|