示例#1
0
 private static void OnListenerRemoved(E_GameEvent eventType)
 {
     if (eventK_ActionV[eventType] == null)
     {
         eventK_ActionV.Remove(eventType);
     }
 }
示例#2
0
 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);
 }
示例#3
0
        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));
            }
        }
示例#4
0
        //————————————————————————————————————

        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));
                }
            }
        }
示例#5
0
        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));
                }
            }
        }
示例#6
0
        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("都没注册进来,移除个蛋");
            }
        }
示例#7
0
 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;
 }
示例#8
0
 public CommonEventBean(E_GameEvent id)
 {
     EventId = id;
 }