# Unity-Command-System **Repository Path**: River314588804/unity-command-system ## Basic Information - **Project Name**: Unity-Command-System - **Description**: 适用于 Unity 平台的简易命令行框架 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-03-31 - **Last Updated**: 2025-11-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: command, Unity ## README # Unity-Command-System 专注于命令系统的简易框架   ## 你应该须知道 1. 你需要在 Unity 生命周期中手动执行一次 `Init()` 以初始化命令集。 2. 你只需要创建你的命令脚本类,CommandManager 会在周期开始时检索继承 ICommand 接口的所有类并实例化。(无须挂载或继承 `MonoBehaviour`) ```csharp CommandManager _commandMgr public void Start() { _commandMgr.Init(); } ``` ## 创建命令 你可以选择新建脚本继承 `RStudio.Command.ICommand` 以实现接口。示例如下: ```csharp public class CommandHello : ICommand { public string Name => "AdminBroadcast"; public string Description => "使用全局广播"; public CommandPermission RequiredPermission => CommandPermission.Normal; public string Category => "General"; public string Usage => "AdminBroadcast [参数]"; public string[] ParamArray { get; set; } = System.Array.Empty(); public bool CanExecute(string[] args) { // 制定你的规则决定是否允许执行 // 你可以选择在 Execute(string[] args) 中直接判断。 return this.ParamArry.Length == args.Length; } public bool Execute(string[] args) { if (!CanExecute(args)) return false; Debug.Log("Hello World!"); return true; } } ``` 你也可以选择菜单 **RStudio/命令系统/命令生成器** 在图形化界面中创建脚本。 该图形化界面的优势 1. 检索是否有已创建命令,避免冲突。 2. 快速浏览和索引具体命令,方便修改。 ![输入图片说明](https://foruda.gitee.com/images/1760452764157529500/b6cec097_14180433.png "屏幕截图")