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/CommandGroup.cs | 96 ++++++++++++++++++++++
1 file changed, 96 insertions(+)
create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs
(limited to 'WorldlineKeepers/Assets/Scripts/Tools/Commands/CommandGroup.cs')
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());
+ //...
+ }
+ }
+
+ */
+
+}
--
cgit v1.1-26-g67d0