diff options
Diffstat (limited to 'YesCommander/Assets/Scripts/Tools/Commands/CommandGroup.cs')
-rw-r--r-- | YesCommander/Assets/Scripts/Tools/Commands/CommandGroup.cs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/YesCommander/Assets/Scripts/Tools/Commands/CommandGroup.cs b/YesCommander/Assets/Scripts/Tools/Commands/CommandGroup.cs new file mode 100644 index 0000000..2a09a0c --- /dev/null +++ b/YesCommander/Assets/Scripts/Tools/Commands/CommandGroup.cs @@ -0,0 +1,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 YC +{ + //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()); + //... + } + } + + */ + +} |