public void Off(string eventName, DelegateEvent.EventHandler callback) { if (actionMap.ContainsKey(eventName)) { actionMap[eventName].removeListener(callback); } }
public void On(string eventName, DelegateEvent.EventHandler callback) { if (!actionMap.ContainsKey(eventName)) { DelegateEvent delegateEvent = new DelegateEvent(); actionMap.Add(eventName, delegateEvent); } actionMap[eventName].addListener(callback); }
/// <summary> /// 删除事件 /// </summary> /// <param name="type">事件类型</param> /// <param name="listenerFunc">监听函数</param> public static void removeEventListener(EventType type, DelegateEvent.EventHandler listenerFunc) { if (listenerFunc == null) { return; } if (!eventTypeListeners.ContainsKey(type)) { return; } DelegateEvent delegateEvent = eventTypeListeners[type]; delegateEvent.removeListener(listenerFunc); }
/// <summary> /// 添加事件 /// </summary> /// <param name="type">事件类型</param> /// <param name="listenerFunc">监听函数</param> public static void addEventListener(EventType type, DelegateEvent.EventHandler listenerFunc) { DelegateEvent delegateEvent; if (eventTypeListeners.ContainsKey(type)) { delegateEvent = eventTypeListeners[type]; } else { delegateEvent = new DelegateEvent(); eventTypeListeners[type] = delegateEvent; } delegateEvent.addListener(listenerFunc); }