/// <summary> /// Add a message into the manager to dispatch. /// </summary> /// <param name="in_rMsg">Message to dispatch.</param> /// <param name="in_iActorID">Actor's ID sending the message.</param> public void AddMessageInManager(AF_Message in_rMsg) { if (in_rMsg != null) { m_qMessagesToDispatch.Enqueue(in_rMsg); } else if (Debug.isDebugBuild) { Debug.LogWarning("rMsg is null."); } }
public void Update() { // dispatch the current messages and clear it while (m_qMessagesToDispatch.Count > 0) { AF_Message msgToDispatch = m_qMessagesToDispatch.Dequeue(); // check if there is any record for the event type in the registry if (m_dictEventListenersRegistry.ContainsKey(msgToDispatch.Type)) { // send the current message to all listeners foreach (AF_MessageHandler currListener in m_dictEventListenersRegistry[msgToDispatch.Type]) { currListener.MessagesToConsume.Add(msgToDispatch); } } } }
/// <summary> /// Checks if there is a message of a certain type, returns it and removes it from the handler's messages. /// </summary> /// <param name="msgType">Type of message to search.</param> /// <returns>Message object. This should be casted based on the type to get all the needed info.</returns> public AF_Message ReceiveMessage(AF_Message.MsgType msgType) { AF_Message msgToReturn = null; if (MessagesToConsume.Count > 0) { foreach (AF_Message msg in MessagesToConsume) { if (msg.Type == msgType) { msgToReturn = msg; MessagesToConsume.Remove(msg); break; } } } return(msgToReturn); }
public AF_Message Clone(AF_Message msgToClone) { return(new AF_Message(msgToClone.Type, msgToClone.Sender)); }
/// <summary> /// Sends the message to the manager. /// </summary> /// <param name="eType">Message type.</param> public void SendMessage(AF_Message in_rMsg) { AF_MessageManager.Instance.AddMessageInManager(in_rMsg); }