using UnityEngine; using System.Collections.Generic; public class CmdManager { private CmdBase m_CurrentCmd; private Queue m_CmdList = new Queue(); public void Enqueue(CmdBase cmd) { m_CmdList.Enqueue(cmd); //Debug.LogFormat("添加待执行命令: {0}", cmd.GetType()); } public void ReplaceCurrent(CmdBase cmd) { m_CmdList.Clear(); m_CurrentCmd = cmd; } public void Update() { if (m_CurrentCmd == null) { if (m_CmdList.Count > 0) { m_CurrentCmd = m_CmdList.Dequeue(); //Debug.LogFormat("开始执行命令: {0}", m_CurrentCmd.GetType()); } if (m_CurrentCmd == null) { return; } } m_CurrentCmd.Update(); if (m_CurrentCmd.Finished()) { //Debug.LogFormat("命令执行完结: {0}", m_CurrentCmd.GetType()); if (m_CmdList.Count > 0) { m_CurrentCmd = m_CmdList.Dequeue(); //Debug.LogFormat("开始执行命令: {0}", m_CurrentCmd.GetType()); } else { m_CurrentCmd = null; //Debug.LogFormat("============== 命令队列完结 ============"); } } } public void Clear() { m_CmdList.Clear(); } }