diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Tools/Commands')
4 files changed, 165 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs b/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs new file mode 100644 index 0000000..120eb08 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public abstract class Command + { + + public abstract void Execute(); + + } + + public class CommandList + { + private List<Command> m_Commands = new List<Command>(); + + public void AddCommand(Command cmd) + { + if (cmd == null) + { + return; + } + m_Commands.Add(cmd); + } + + public void RemoveCommand(Command cmd) + { + if (cmd == null) + { + return; + } + m_Commands.Remove(cmd); + } + + public void Execute() + { + for (int i = 0; i < m_Commands.Count; ++i) + { + m_Commands[i].Execute(); + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs.meta new file mode 100644 index 0000000..651a018 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f81999dab5f39be408c8e5c5f809eddf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs b/WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs new file mode 100644 index 0000000..8e53888 --- /dev/null +++ b/WorldlineKeepers/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 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()); + //... + } + } + + */ + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs.meta new file mode 100644 index 0000000..3df093c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 61d8f0e869532c64395b21a493d17a45 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |