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(); +} +