mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
新增 `ArchitecturePhase` 枚举及生命周期接口,支持在不同阶段执行相应逻辑。 实现基于阶段的状态转换控制与校验,增强架构初始化流程的可控性与扩展性。 添加模块安装接口 `IArchitectureModule` 及相关感知接口,便于插件化集成。 完善系统与模型注册限制,禁止在就绪后注册组件,提升运行时稳定性。 移除旧版补丁注册机制,统一通过生命周期钩子进行扩展。
63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using GFramework.Core.architecture;
|
||
using Godot;
|
||
|
||
namespace GFramework.Godot.architecture;
|
||
|
||
/// <summary>
|
||
/// 抽象架构类,为特定类型的架构提供基础实现框架
|
||
/// </summary>
|
||
/// <typeparam name="T">架构的具体类型,必须继承自Architecture且能被实例化</typeparam>
|
||
public abstract class AbstractArchitecture<T> : Architecture<T> where T : Architecture<T>, new()
|
||
{
|
||
private const string ArchitectureName = "__GFramework__Architecture__Anchor";
|
||
/// <summary>
|
||
/// 初始化架构,按顺序注册模型、系统和工具
|
||
/// </summary>
|
||
protected override void Init()
|
||
{
|
||
RegisterModels();
|
||
RegisterSystems();
|
||
RegisterUtilities();
|
||
AttachToGodotLifecycle();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将架构绑定到Godot生命周期中,确保在场景树销毁时能够正确清理资源
|
||
/// 通过创建一个锚节点来监听场景树的销毁事件
|
||
/// </summary>
|
||
private void AttachToGodotLifecycle()
|
||
{
|
||
if (Engine.GetMainLoop() is not SceneTree tree)
|
||
return;
|
||
|
||
// 防止重复挂载(热重载 / 多次 Init)
|
||
if (tree.Root.GetNodeOrNull(ArchitectureName) != null)
|
||
return;
|
||
|
||
var anchor = new ArchitectureAnchorNode
|
||
{
|
||
Name = ArchitectureName
|
||
};
|
||
|
||
anchor.Bind(Destroy);
|
||
|
||
tree.Root.CallDeferred(Node.MethodName.AddChild, anchor);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注册工具抽象方法,由子类实现具体的工具注册逻辑
|
||
/// </summary>
|
||
protected abstract void RegisterUtilities();
|
||
|
||
/// <summary>
|
||
/// 注册系统抽象方法,由子类实现具体系统注册逻辑
|
||
/// </summary>
|
||
protected abstract void RegisterSystems();
|
||
|
||
/// <summary>
|
||
/// 注册模型抽象方法,由子类实现具体模型注册逻辑
|
||
/// </summary>
|
||
protected abstract void RegisterModels();
|
||
}
|
||
|