feat(core): 添加架构初始化完成事件

- 在架构初始化完成后发送 ArchitectureInitializedEvent 事件
- 新增 ArchitectureEvents 类用于定义架构相关事件
- 修改 AbstractResourceFactorySystem 在架构初始化完成后执行资源预加载
- 移除 AbstractArchitecture 中的多余空行
This commit is contained in:
GwWuYou 2025-12-17 21:07:36 +08:00
parent 4157ef1384
commit a444581ec7
4 changed files with 22 additions and 5 deletions

View File

@ -10,7 +10,6 @@ namespace GFramework.Core.Godot.architecture;
public abstract class AbstractArchitecture<T> : Architecture<T> where T : Architecture<T>, new()
{
private const string ArchitectureName = "__GFrameworkArchitectureAnchor";
/// <summary>
/// 初始化架构,按顺序注册模型、系统和工具
/// </summary>

View File

@ -1,4 +1,5 @@
using GFramework.Core.extensions;
using GFramework.Core.events;
using GFramework.Core.extensions;
using GFramework.Core.system;
using Godot;
@ -25,9 +26,14 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
_registry = new ResourceFactory.Registry();
_resourceLoadSystem = this.GetSystem<IResourceLoadSystem>();
_assetCatalogSystem = this.GetSystem<IAssetCatalogSystem>();
// 注册资源
RegisterResources();
// 执行预加载
_registry.PreloadAll();
// 监听架构初始化事件
this.RegisterEvent<ArchitectureEvents.ArchitectureInitializedEvent>(_ =>
{
// 预加载所有资源
_registry.PreloadAll();
});
}
/// <summary>

View File

@ -46,7 +46,8 @@ public abstract class Architecture<T> : IArchitecture where T : Architecture<T>,
foreach (var system in arch._mSystems) system.Init();
arch._mSystems.Clear();
// 发送架构初始化完成事件
arch.SendEvent(new ArchitectureEvents.ArchitectureInitializedEvent());
arch._mInited = true;
return arch;
}, LazyThreadSafetyMode.ExecutionAndPublication);

View File

@ -0,0 +1,11 @@

namespace GFramework.Core.events;
public static class ArchitectureEvents
{
/// <summary>
/// 架构初始化完成事件
/// 在所有 Model / System Init 执行完毕后派发
/// </summary>
public readonly struct ArchitectureInitializedEvent { }
}