public void AddMessageHandler(string msgId, MessageHandlerDelegate action)
        {
            CSharpMessageHandler handler = new CSharpMessageHandler();

            handler.MessageId = msgId;
            handler.Delegate  = action;
            m_MessageHandlers.Add(handler);
        }
        public CSharpMessageHandler Clone()
        {
            CSharpMessageHandler handler = new CSharpMessageHandler();

            handler.m_MessageId = m_MessageId;
            handler.m_Delegate  = m_Delegate;
            return(handler);
        }
        public void Tick(long curTime)
        {
            const int c_MaxMsgCountPerTick = 256;
            long      delta = 0;

            if (m_LastTickTime == 0)
            {
                m_LastTickTime = curTime;
            }
            else
            {
                delta          = curTime - m_LastTickTime;
                m_LastTickTime = curTime;
                m_CurTime     += delta;
            }

            foreach (CSharpMessageHandler handler in m_MessageHandlers)
            {
                string msgId = handler.MessageId;
                Queue <MessageInfo> queue;
                if (m_MessageQueues.TryGetValue(msgId, out queue))
                {
                    for (int msgCt = 0; msgCt < c_MaxMsgCountPerTick && queue.Count > 0; ++msgCt)
                    {
                        MessageInfo          info          = queue.Dequeue();
                        CSharpMessageHandler activeHandler = handler.Clone();
                        activeHandler.Trigger(this, info.m_Args);
                        m_ActiveHandlers.Add(activeHandler);
                    }
                }
            }
            int ct = m_ParallelCommands.Count;

            for (int ix = ct - 1; ix >= 0; --ix)
            {
                ICommand cmd = m_ParallelCommands[ix];
                if (cmd.Execute(this, delta) == ExecResult.Finished)
                {
                    cmd.Reset();
                    m_ParallelCommands.Remove(cmd);
                }
            }
            ct = m_ActiveHandlers.Count;
            for (int ix = ct - 1; ix >= 0; --ix)
            {
                long dt = delta;
                CSharpMessageHandler handler = m_ActiveHandlers[ix];
                handler.Tick(this, dt);
                if (handler.IsFinished())
                {
                    m_ActiveHandlers.RemoveAt(ix);
                }
            }
        }
        public void Reset()
        {
            m_IsTerminated = false;
            int ct = m_MessageHandlers.Count;

            for (int i = ct - 1; i >= 0; --i)
            {
                CSharpMessageHandler handler = m_MessageHandlers[i];
                handler.Reset();
                Queue <MessageInfo> queue;
                if (m_MessageQueues.TryGetValue(handler.MessageId, out queue))
                {
                    queue.Clear();
                }
            }

            m_DisableMoveInput     = false;
            m_DisableRotationInput = false;
            m_Velocity             = Vector3.zero;

            m_ActiveHandlers.Clear();
            m_ParallelCommands.Clear();
            m_LocalVariables.Clear();
        }