blob: 8e53888dc930107127bc9aabc738c0e056afdf67 (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics.Tracing;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;
namespace WK
{
//http://warmcat.org/chai/blog/?p=2343
public abstract class CommandsGroup
{
public abstract class Command
{
public CommandID ID;
public Command(CommandID id)
{
this.ID = id;
}
/// <summary>
/// 执行命令
/// </summary>
public abstract void Execute();
/// <summary>
/// 注册命令的参数
/// </summary>
/// <param name="_param"></param>
public abstract void Register(params object[] _param);
}
protected List<Command> commandQueue = new List<Command>();
protected void AddCommand(Command cmd)
{
commandQueue.Add(cmd);
}
public CommandsGroup()
{
SetupCommands();
}
/// <summary>
/// 填充 commandQueue
/// </summary>
protected abstract void SetupCommands();
public void Execute()
{
foreach (Command e in commandQueue)
{
e.Execute();
}
}
public void RegisterParams(params object[] data)
{
if (data.Length < 1)
return;
CommandID id = (CommandID)data[0];
int len = data.Length;
foreach (Command e in commandQueue)
{
if (e.ID == id)
{
e.Register(data.Skip(1).Take(len - 1));
break;
}
}
}
}
/*
/// <summary>
/// 主场景打开时执行的命令集合
/// </summary>
class MainSceneLoadCommandsGroup : CommandsGroup
{
public MainSceneLoadCommandsGroup() : base()
{
// 设置需要执行的命令
AddCommand(new OpenPanelCommand());
// 其他命令
//AddCommand(new MessageBox());
//AddCommand(new OpenChest());
//...
}
}
*/
}
|