コード例 #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();


            for (int i = 0; i < mWorkQueue.Count; i++)
            {
                SafeWorkItemClass SafeWorkItem;
                mWorkQueue.Dequeue(out SafeWorkItem);
                i--;
                if (SafeWorkItem != null)
                {
                    TaskManager.CreateTask(CoroutineFactory.GenerateCoroutine(new Action(() =>
                    {
                        SafeWorkItem.Run();
                    })
                                                                              ), (@bool) => { }).Start();
                }
            }
            mWorkQueue.Clear();
        }
コード例 #2
0
ファイル: TaskManager.cs プロジェクト: jesenzhang/GameBase
 public static TaskState JSCreateTask(params object[] @params)
 {
     // CoroutineFactory.GenerateCoroutine(@params);
     return(CreateTask(CoroutineFactory.GenerateCoroutine(@params), (@bool) => { }));
 }