From 2afbb545027568fccc85853e18af02a7c6b2929e Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Tue, 16 May 2023 16:03:51 +0800 Subject: *misc --- .../Assets/Scripts/Tools/Commands/Command.cs | 47 +++++++++++ .../Assets/Scripts/Tools/Commands/Command.cs.meta | 11 +++ .../Assets/Scripts/Tools/Commands/CommandGroup.cs | 96 ++++++++++++++++++++++ .../Scripts/Tools/Commands/CommandGroup.cs.meta | 11 +++ 4 files changed, 165 insertions(+) create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Commands/Command.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs.meta (limited to 'WorldlineKeepers/Assets/Scripts/Tools/Commands') 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 m_Commands = new List(); + + 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; + } + /// + /// 执行命令 + /// + public abstract void Execute(); + /// + /// 注册命令的参数 + /// + /// + public abstract void Register(params object[] _param); + } + + protected List commandQueue = new List(); + protected void AddCommand(Command cmd) + { + commandQueue.Add(cmd); + } + + public CommandsGroup() + { + SetupCommands(); + } + + /// + /// 填充 commandQueue + /// + 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; + } + } + } + } + + /* + /// + /// 主场景打开时执行的命令集合 + /// + 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: -- cgit v1.1-26-g67d0