From 259c4411c7db630c9628a1b5d0931e436c7620d7 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 21 Dec 2025 13:31:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(architecture):=20=E9=87=8D=E6=9E=84God?= =?UTF-8?q?ot=E6=9E=B6=E6=9E=84=E6=89=A9=E5=B1=95=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=E4=B8=BA=E6=A8=A1=E5=9D=97=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原有的IGodotArchitectureExtension接口及其实现统一替换为IGodotModule接口, 以提供更清晰、更具扩展性的模块化支持。同时更新了相关字段和方法命名, 使其语义更加准确,提升代码可读性和维护性。 --- .../architecture/AbstractArchitecture.cs | 24 +++++++++------- .../IGodotArchitectureExtension.cs | 11 -------- GFramework.Godot/architecture/IGodotModule.cs | 28 +++++++++++++++++++ 3 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 GFramework.Godot/architecture/IGodotArchitectureExtension.cs create mode 100644 GFramework.Godot/architecture/IGodotModule.cs diff --git a/GFramework.Godot/architecture/AbstractArchitecture.cs b/GFramework.Godot/architecture/AbstractArchitecture.cs index e02546f..c659fb8 100644 --- a/GFramework.Godot/architecture/AbstractArchitecture.cs +++ b/GFramework.Godot/architecture/AbstractArchitecture.cs @@ -21,7 +21,7 @@ public abstract class AbstractArchitecture : Architecture where T : Archit /// 存储所有已安装的Godot架构扩展组件列表 /// 用于在架构销毁时正确清理所有扩展资源 /// - private readonly List> _extensions = []; + private readonly List> _extensions = []; /// /// 架构锚点节点引用 @@ -81,32 +81,36 @@ public abstract class AbstractArchitecture : Architecture where T : Archit tree.Root.CallDeferred(Node.MethodName.AddChild, _anchor); } - + /// - /// 安装Godot架构扩展组件 + /// 安装Godot模块扩展 /// - /// 要安装的Godot架构扩展实例,必须实现IGodotArchitectureExtension接口 - /// 异步任务,表示扩展安装过程 - protected async Task InstallGodotExtension(IGodotArchitectureExtension extension) + /// 模块类型,必须实现IGodotModule接口 + /// 要安装的模块实例 + /// 异步任务 + protected async Task InstallGodotModule(TModule module) where TModule : IGodotModule { + module.Install(this); + // 检查锚点是否已初始化,未初始化则抛出异常 if (_anchor == null) throw new InvalidOperationException("Anchor not initialized"); - + // 等待锚点准备就绪 await _anchor.WaitUntilReady(); // 延迟调用将扩展节点添加为锚点的子节点 - _anchor.CallDeferred(Node.MethodName.AddChild, extension.Node); + _anchor.CallDeferred(Node.MethodName.AddChild, module.Node); // 调用扩展的附加回调方法 - extension.OnAttach(this); + module.OnAttach(this); // 将扩展添加到扩展集合中 - _extensions.Add(extension); + _extensions.Add(module); } + /// /// 销毁架构及其相关资源。 /// 调用所有已安装扩展的OnDetach方法,并清空扩展列表。 diff --git a/GFramework.Godot/architecture/IGodotArchitectureExtension.cs b/GFramework.Godot/architecture/IGodotArchitectureExtension.cs deleted file mode 100644 index 70a69e3..0000000 --- a/GFramework.Godot/architecture/IGodotArchitectureExtension.cs +++ /dev/null @@ -1,11 +0,0 @@ -using GFramework.Core.architecture; -using Godot; - -namespace GFramework.Godot.architecture; - -public interface IGodotArchitectureExtension where T : Architecture, new() -{ - Node Node { get; } - void OnAttach(Architecture architecture); - void OnDetach(); -} diff --git a/GFramework.Godot/architecture/IGodotModule.cs b/GFramework.Godot/architecture/IGodotModule.cs new file mode 100644 index 0000000..7242005 --- /dev/null +++ b/GFramework.Godot/architecture/IGodotModule.cs @@ -0,0 +1,28 @@ +using GFramework.Core.architecture; +using Godot; + +namespace GFramework.Godot.architecture; + +/// +/// Godot模块接口,定义了Godot引擎中模块的基本行为和属性 +/// +/// 架构类型,必须继承自Architecture<T>且具有无参构造函数 +public interface IGodotModule : IArchitectureModule where T : Architecture, new() +{ + /// + /// 获取模块关联的Godot节点 + /// + Node Node { get; } + + /// + /// 当模块被附加到架构时调用 + /// + /// 要附加到的架构实例 + void OnAttach(Architecture architecture); + + /// + /// 当模块从架构分离时调用 + /// + void OnDetach(); +} +