private void AddEventTriggerEvent(Component obj, EventTriggerType eventType, UnityAction<BaseEventData> callback) { EventTrigger.Entry entry = null; EventTrigger trigger = obj.GetComponent<EventTrigger>(); if (trigger != null) // 已有EventTrigger { // 查找是否已经存在要注册的事件 foreach (EventTrigg...
usingUnityEngine;usingUnityEngine.EventSystems;publicclassEventTriggerListener : EventTrigger {publicdelegatevoidVoidDelegate();publicdelegatevoidEventDelegate(BaseEventData baseEventData);publicdelegatevoidBoolDelegate(boolstate);publicdelegatevoidFloatDelegate(floatdelta);publicdelegatevoidVectorDelegate(Vector2 delta)...
private void AddTriggersListener(GameObject gameobject1, EventTriggerType eventID, UnityAction<BaseEventData> unityAction1) {//第一个参数是Unity3D的舞台对象GameObject,第二个参数是监听事件类型,最后一个是监听的回调函数 /*看对象本身是否有EventTrigger这个组件,没则创建个*/ EventTrigger trigger; if (gameobj...
public static EventTriggerListener Get(GameObject obj) { EventTriggerListener eventTriggerListener = obj.GetComponent<EventTriggerListener>(); if (eventTriggerListener == null) { eventTriggerListener = obj.AddComponent<EventTriggerListener>(); } return eventTriggerListener; } /// /// 判断是否是第二次点...
eventTriggerListener= go.AddComponent<EventTriggerListener>(); }returneventTriggerListener; }publicoverridevoidOnPointerClick(PointerEventData eventData) {base.OnPointerClick(eventData); onClick?.Invoke(gameObject); }publicoverridevoidOnPointerEnter(PointerEventData eventData) ...
public class EventTriggerListener :UnityEngine.EventSystems.EventTrigger { public delegate void VoidDelegate(GameObject go); public VoidDelegate onClick; public VoidDelegate onDown; public VoidDelegate onEnter; public VoidDelegate onExit; public VoidDelegate onUp; ...
EventTriggerListener.Get(cube).onClick = OnButtonClick; } private void OnButtonClick(GameObject go) { //在这里监听按钮的点击事件 if (go == button.gameObject) { Debug.Log("DoSomeThings"); } if (go == image.gameObject) { Debug.Log("DoSomeThings1"); ...
包括所有鼠标操作的各种事件,不知道意思的翻译一下就明白了。 三、UI点击事件处理方法。 可通过一个类来解决所有UI事件中的实现绑定方法,用此代码方便UI事件的统一管理。 usingUnityEngine;usingUnityEngine.EventSystems;publicclassEventTriggerListener:UnityEngine.EventSystems.EventTrigger{//定义出发事件中绑定的委托publ...
添加EventTrigger 代码 privatevoidAddTriggersListener(GameObjectobj,EventTriggerTypeeventType,UnityAction<BaseEventData>action){//首先判断对象是否已经有EventTrigger组件,若没有那么需要添加EventTriggertrigger=obj.GetComponent<EventTrigger>();if(trigger==null){trigger=obj.AddComponent<EventTrigger>();}//实例化deleg...
EventTriggerListenerlistener=go.GetComponent(); if(listener==null)listener=go.AddComponent(); returnlistener; } publicoverridevoidOnPointerClick(PointerEventDataeventData) { if(onClick!=null)onClick(gameObject); } publicoverridevoidOnPointerDown(PointerEventDataeventData){ ...