/// <summary> /// Subscribes an action to a string. The action gets invoked everytime the messageQueue is popped. /// </summary> /// <param name="msg"></param> /// <param name="a"></param> public void _StartListening(string msg, Func <Message, MessageReturnType> f, MethodPriority p = MethodPriority.Default, bool persist = false) { MessageAction <MessageReturnType> messageAction = new MessageAction <MessageReturnType>(f, p, persist); if (messageReturnDict.ContainsKey(msg) && messageReturnDict[msg].Contains(messageAction)) { throw new MessagingException("Messages of type: " + msg + " are allready executing action " + f.Method.ToString()); } if (messageReturnDictAddList.ContainsKey(msg)) { MessageAction <MessageReturnType> validateAction = messageReturnDictAddList[msg].FirstOrDefault(msga => msga.action == f); if (validateAction != default(MessageAction <MessageReturnType>)) { throw new MessagingException("You are trying to add the same action to the same message type twice."); } messageReturnDictAddList[msg].Add(messageAction); } else { messageReturnDictAddList.Add(msg, new List <MessageAction <MessageReturnType> >()); messageReturnDictAddList[msg].Add(messageAction); } }
/// <summary> /// Subscribes an action to a string. The action gets invoked everytime the messageQueue is popped. /// References GameManager.instance.messageHub. /// </summary> /// <param name="msg"></param> /// <param name="a"></param> /// <param name="p">The priority with which the message shoudl be invoked</param> public static void StartListening(string msg, Action <Message> a, MethodPriority p) { try { _distributor.messageHub._StartListening(msg, a, (int)p); } catch (NullReferenceException e) { throw new MessagingException(e.Message, e); } }
public MessageAction(Action <Message> a, MethodPriority p, bool persist) { the_action = a; this.persist = persist; priority = (int)p; }
public static void StartListeningWithReturn(string msg, Func <Message, MessageReturnType> f, MethodPriority p) { try { _distributor.messageHub._StartListening(msg, f, p); } catch (NullReferenceException e) { throw new MessagingException(e.Message, e); } }