// Update is called once per frame
        void Update()
        {
            float timer = 0.0f;

            while (MessageQueue.Count > 0)
            {
                if (MaxQueueProcessingTime > 0.0f)
                {
                    if (timer > MaxQueueProcessingTime)
                    {
                        return;
                    }
                }

                OfficerBaseMessage msg = MessageQueue.Dequeue();
                if (!TriggerMessage(msg))
                {
                    TinyLogger.Instance.DebugLog("$ Error when processing " +
                                                 " message: " + msg.Name);
                }

                if (MaxQueueProcessingTime > 0.0f)
                {
                    timer += Time.deltaTime;
                }
            }
        }
예제 #2
0
        bool HandleMyCustomMessage(OfficerBaseMessage msg)
        {
            MyCustomMessage castMsg = msg as MyCustomMessage;

            TinyLogger.Instance.DebugLog(string.Format("$ Got the message !" +
                                                       "{0}, {1}", castMsg._intValue, castMsg._floatValue));

            return(true);
        }
        public bool QueueMessage(OfficerBaseMessage msg)
        {
            if (!ListenerDict.ContainsKey(msg.Name))
            {
                return(false);
            }

            MessageQueue.Enqueue(msg);
            return(true);
        }
        public bool TriggerMessage(OfficerBaseMessage msg)
        {
            string msgName = msg.Name;

            if (!ListenerDict.ContainsKey(msgName))
            {
                TinyLogger.Instance.DebugLog("$MessagingSytem: Message \"" +
                                             msgName + "\" has no listeners!");
                return(false);
            }

            List <MessageHandlerDelegate> listenerList = ListenerDict[msgName];

            for (int i = 0; i < listenerList.Count; ++i)
            {
                if (listenerList[i](msg))
                {
                    return(true);
                }
            }

            return(true);
        }