Example #1
0
 static void OnListenerAdding(MessengerEventType eventkey, Delegate listenerDelegate)
 {
     if (!eventTable.ContainsKey(eventkey))
     {
         eventTable.Add(eventkey, null);
     }
 }
Example #2
0
 static public void OnListenerRemoved(MessengerEventType eventType)
 {
     if (eventTable[eventType] == null)
     {
         eventTable.Remove(eventType);
     }
 }
Example #3
0
 static void OnBroadcast(MessengerEventType eventtype)
 {
     if (!eventTable.ContainsKey(eventtype))
     {
         throw new ListenerException("不包含此监听");
     }
 }
Example #4
0
    static public void MarkAsPermanent(MessengerEventType eventType)
    {
#if LOG_ALL_MESSAGES
        Debug.Log("Messenger MarkAsPermanent \t\"" + eventType + "\"");
#endif

        permanentMessages.Add(eventType);
    }
Example #5
0
    static public void OnBroadcasting(MessengerEventType eventType)
    {
#if REQUIRE_LISTENER
        if (!eventTable.ContainsKey(eventType))
        {
            throw new BroadcastException(string.Format("Broadcasting message \"{0}\" but no listener found. Try marking the message with Messenger.MarkAsPermanent.", eventType));
        }
#endif
    }
Example #6
0
    public static void Broadcast(MessengerEventType eventtype)
    {
        OnBroadcast(eventtype);
        CallBack callback;

        if (eventTable.ContainsKey(eventtype))
        {
            callback = eventTable[eventtype] as CallBack;
            callback();//如果不为空调用,unity2017以下不可简写
        }
    }
Example #7
0
    public static void Broadcast <T, D, U>(MessengerEventType eventtype, T t, D d, U u)
    {
        CallBack <T, D, U> callback;

        if (eventTable.ContainsKey(eventtype))
        {
            callback = eventTable[eventtype] as CallBack <T, D, U>;
            if (null != callback)
            {
                callback(t, d, u); //如果不为空调用,unity2017以下不可简写
            }
        }
    }
Example #8
0
    public static void Broadcast <T>(MessengerEventType eventtype, T t)
    {
        OnBroadcast(eventtype);
        CallBack <T> callback;

        if (eventTable.ContainsKey(eventtype))
        {
            callback = eventTable[eventtype] as CallBack <T>;
            if (null != callback)
            {
                callback(t);//如果不为空调用,unity2017以下不可简写
            }
        }
    }
Example #9
0
    static public void OnListenerAdding(MessengerEventType eventType, Delegate listenerBeingAdded)
    {
#if LOG_ALL_MESSAGES || LOG_ADD_LISTENER
        Debug.Log("MESSENGER OnListenerAdding \t\"" + eventType + "\"\t{" + listenerBeingAdded.Target + " -> " + listenerBeingAdded.Method + "}");
#endif

        if (!eventTable.ContainsKey(eventType))
        {
            eventTable.Add(eventType, null);
        }

        Delegate d = eventTable[eventType];
        if (d != null && d.GetType() != listenerBeingAdded.GetType())
        {
            throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
        }
    }
Example #10
0
    static public void OnListenerRemoving(MessengerEventType eventType, Delegate listenerBeingRemoved)
    {
        if (eventTable.ContainsKey(eventType))
        {
            Delegate d = eventTable[eventType];

            if (d == null)
            {
                throw new ListenerException(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType));
            }
            else if (d.GetType() != listenerBeingRemoved.GetType())
            {
                throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
            }
        }
        else
        {
            //throw new ListenerException(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType));
        }
    }
Example #11
0
    //Three parameters
    static public void Broadcast <T, U, V>(MessengerEventType eventType, T arg1, U arg2, V arg3)
    {
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
        Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
#endif
        OnBroadcasting(eventType);

        Delegate d;
        if (eventTable.TryGetValue(eventType, out d))
        {
            MessengerCallback <T, U, V> MessengerCallback = d as MessengerCallback <T, U, V>;

            if (MessengerCallback != null)
            {
                MessengerCallback(arg1, arg2, arg3);
            }
            else
            {
                throw CreateBroadcastSignatureException(eventType);
            }
        }
    }
Example #12
0
    static public void OnListenerRemoving(MessengerEventType eventType, Delegate listenerBeingRemoved)
    {
#if LOG_ALL_MESSAGES
        Debug.Log("MESSENGER OnListenerRemoving \t\"" + eventType + "\"\t{" + listenerBeingRemoved.Target + " -> " + listenerBeingRemoved.Method + "}");
#endif

        if (eventTable.ContainsKey(eventType))
        {
            Delegate d = eventTable[eventType];

            if (d == null)
            {
                throw new ListenerException(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType));
            }
            else if (d.GetType() != listenerBeingRemoved.GetType())
            {
                throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
            }
        }
        else
        {
            throw new ListenerException(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType));
        }
    }
Example #13
0
 static public void RemoveListener <T, D>(MessengerEventType eventType, CallBack <T, D> handler)
 {
     OnListenerRemoving(eventType, handler);
     eventTable[eventType] = (CallBack <T, D>)eventTable[eventType] - handler;
     OnListenerRemoved(eventType);
 }
Example #14
0
 /// <summary>
 /// Removes the listener.
 /// </summary>
 /// <param name="eventType">Event type.</param>
 /// <param name="handler">Handler.</param>
 static public void RemoveListener(MessengerEventType eventType, Callback handler)
 {
     RemoveListener(eventType.ToString(), handler);
 }
Example #15
0
 static public BroadcastException CreateBroadcastSignatureException(MessengerEventType eventType)
 {
     return(new BroadcastException(string.Format("Broadcasting message \"{0}\" but listeners have a different signature than the broadcaster.", eventType)));
 }
Example #16
0
		/// <summary>
		/// Broadcast the specified eventType and mode.
		/// </summary>
		/// <param name="eventType">Event type.</param>
		/// <param name="mode">Mode.</param>
		static public void Broadcast (MessengerEventType eventType, MessengerMode mode)
		{
				Broadcast (eventType.ToString (), mode);
		}
Example #17
0
 public static void AddListener <T, D, U>(MessengerEventType eventtype, CallBack <T, D, U> handler)
 {
     OnListenerAdding(eventtype, handler);
     eventTable[eventtype] = (eventTable[eventtype] as CallBack <T, D, U>) + (handler);
 }
Example #18
0
 //Three parameters
 static public void AddListener <T, U, V>(MessengerEventType eventType, MessengerCallback <T, U, V> handler)
 {
     OnListenerAdding(eventType, handler);
     eventTable[eventType] = (MessengerCallback <T, U, V>)eventTable[eventType] + handler;
 }
Example #19
0
 //Three parameters
 static public void RemoveListener <T, U, V>(MessengerEventType eventType, MessengerCallback <T, U, V> handler)
 {
     OnListenerRemoving(eventType, handler);
     eventTable[eventType] = (MessengerCallback <T, U, V>)eventTable[eventType] - handler;
     OnListenerRemoved(eventType);
 }
Example #20
0
 /// <summary>
 /// Broadcast the specified eventType.
 /// </summary>
 /// <param name="eventType">Event type.</param>
 static public void Broadcast(MessengerEventType eventType)
 {
     Broadcast(eventType.ToString(), MessengerInternal.DEFAULT_MODE);
 }
Example #21
0
		/// <summary>
		/// Broadcast the specified eventType.
		/// </summary>
		/// <param name="eventType">Event type.</param>
		static public void Broadcast (MessengerEventType eventType)
		{
				Broadcast (eventType.ToString (), MessengerInternal.DEFAULT_MODE);
		}
Example #22
0
 /// <summary>
 /// Broadcast the specified eventType and mode.
 /// </summary>
 /// <param name="eventType">Event type.</param>
 /// <param name="mode">Mode.</param>
 static public void Broadcast(MessengerEventType eventType, MessengerMode mode)
 {
     Broadcast(eventType.ToString(), mode);
 }
Example #23
0
		/// <summary>
		/// Removes the listener.
		/// </summary>
		/// <param name="eventType">Event type.</param>
		/// <param name="handler">Handler.</param>
		static public void RemoveListener (MessengerEventType eventType, Callback handler)
		{
				RemoveListener (eventType.ToString (), handler);
		}