コード例 #1
0
        /// <summary>
        /// Raised each tick so we can determine if it's time to send delayed messages
        /// </summary>
        public static void Update()
        {
            // Process the messages and determine if it's time to send them
            for (int i = 0; i < mMessages.Count; i++)
            {
                IMessage lMessage = mMessages[i];

                // Reduce the delay
                lMessage.Delay -= Time.deltaTime;
                if (lMessage.Delay < 0)
                {
                    lMessage.Delay = EnumMessageDelay.IMMEDIATE;
                }

                // If it's time, send the message and flag for removal
                if (!lMessage.IsSent && lMessage.Delay == EnumMessageDelay.IMMEDIATE)
                {
                    SendMessage(lMessage);
                }
            }

            // Remove sent messages
            for (int i = mMessages.Count - 1; i >= 0; i--)
            {
                IMessage lMessage = mMessages[i];
                if (lMessage.IsSent || lMessage.IsHandled)
                {
                    mMessages.RemoveAt(i);

                    // If a message is handled (done being processed),
                    // we'll release it for reuse.
                    if (lMessage.IsHandled)
                    {
                        Message.Release(lMessage);
                    }
                }
            }

            // Remove listeners
            for (int i = mListenerRemoves.Count - 1; i >= 0; i--)
            {
                RemoveListener(mListenerRemoves[i]);
            }

            mListenerRemoves.Clear();

            // Add Listeners
            for (int i = mListenerAdds.Count - 1; i >= 0; i--)
            {
                AddListener(mListenerAdds[i]);
            }

            mListenerAdds.Clear();
        }
コード例 #2
0
        /// <summary>
        /// Create and send a message object
        /// </summary>
        /// <param name="rType">Type of message to send</param>
        /// <param name="rFilter">Filter to send only to those listening to the filter</param>
        public static void SendMessage(string rType, string rFilter)
        {
            // Create the message
            Message lMessage = Message.Allocate();

            lMessage.Sender    = null;
            lMessage.Recipient = rFilter;
            lMessage.Type      = rType;
            lMessage.Data      = null;
            lMessage.Delay     = EnumMessageDelay.IMMEDIATE;

            // Send it or store it
            SendMessage(lMessage);

            // Free up the message since we created it
            Message.Release(lMessage);
        }
コード例 #3
0
        /// <summary>
        /// Create and send a message object
        /// </summary>
        /// <param name="rSender">Sender</param>
        /// <param name="rRecipient">Recipient name to send to</param>
        /// <param name="rType">Type of message to send</param>
        /// <param name="rData">Data to send</param>
        /// <param name="rDelay">Seconds to delay</param>
        public static void SendMessage(object rSender, string rRecipient, string rType, object rData, float rDelay)
        {
            // Create the message
            Message lMessage = Message.Allocate();

            lMessage.Sender    = rSender;
            lMessage.Recipient = rRecipient;
            lMessage.Type      = rType;
            lMessage.Data      = rData;
            lMessage.Delay     = rDelay;

            // Send it or store it
            SendMessage(lMessage);

            // Free up the message since we created it
            if (rDelay == EnumMessageDelay.IMMEDIATE)
            {
                lMessage.Release();
            }
        }
コード例 #4
0
        /// <summary>
        /// Create and send a message object
        /// </summary>
        /// <param name="rType">Type of message to send</param>
        public static void SendMessage(string rType, float rDelay = 0f)
        {
            // Create the message
            Message lMessage = Message.Allocate();

            lMessage.Sender    = null;
            lMessage.Recipient = "";
            lMessage.Type      = rType;
            lMessage.Data      = null;
            lMessage.Delay     = rDelay;

            // Send it or store it
            SendMessage(lMessage);

            // Free up the message since we created it
            if (rDelay == EnumMessageDelay.IMMEDIATE)
            {
                lMessage.Release();
            }
        }