少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System.Collections.Generic;
 
public class CmdManager
{
    private CmdBase m_CurrentCmd;
    private Queue<CmdBase> m_CmdList = new Queue<CmdBase>();
 
    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();
    }
}