private static void OnListenerRemoved(E_GameEvent eventType) { if (eventK_ActionV[eventType] == null) { eventK_ActionV.Remove(eventType); } }
public static void RemoveListener <T, U, V, X>(E_GameEvent eventType, Callback <T, U, V, X> handler) { OnListenerRemoving(eventType, handler); // ReSharper disable once DelegateSubtraction eventK_ActionV[eventType] = (Callback <T, U, V, X>)eventK_ActionV[eventType] - handler; OnListenerRemoved(eventType); }
private static void OnListenerAdding(E_GameEvent eventType, Delegate listenerBeingAdded) { if (!eventK_ActionV.ContainsKey(eventType)) { eventK_ActionV.Add(eventType, null); } Delegate d = eventK_ActionV[eventType]; if (d != null && d.GetType() != listenerBeingAdded.GetType()) { throw new Exception(string.Format("事件 —{0}—, 不一致的监听器,当前要添加的是 —{1}— ,之前的是 —{2}—", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name)); } }
//———————————————————————————————————— public static void SendEvent(E_GameEvent eventType) { Delegate d; if (eventK_ActionV.TryGetValue(eventType, out d)) { Callback callback = d as Callback; if (callback != null) { callback(); } else { throw new Exception(string.Format("发送消息:{0},接收者参数与发送者的参数不同 ", eventType)); } } }
public static void SendEvent <T, U, V, X>(E_GameEvent eventType, T arg1, U arg2, V arg3, X arg4) { Delegate d; if (eventK_ActionV.TryGetValue(eventType, out d)) { Callback <T, U, V, X> callback = d as Callback <T, U, V, X>; if (callback != null) { callback(arg1, arg2, arg3, arg4); } else { throw new Exception(string.Format("发送消息:{0},接收者参数与发送者的参数不同 ", eventType)); } } }
private static void OnListenerRemoving(E_GameEvent eventType, Delegate listenerBeingRemoved) { if (eventK_ActionV.ContainsKey(eventType)) { Delegate d = eventK_ActionV[eventType]; if (d == null) { MyLog.Red("移除的事件为空 —— " + eventType); } else if (d.GetType() != listenerBeingRemoved.GetType()) { throw new Exception(string.Format("事件 —{0}—, 不一致的监听器,当前移除的是 —{1}— ,之前的是 —{2}—", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name)); } } else { MyLog.Red("都没注册进来,移除个蛋"); } }
public static void AddListener <T, U, V, X>(E_GameEvent eventType, Callback <T, U, V, X> handler) { OnListenerAdding(eventType, handler); eventK_ActionV[eventType] = (Callback <T, U, V, X>)eventK_ActionV[eventType] + handler; }
public CommonEventBean(E_GameEvent id) { EventId = id; }