From 8df2b071cfbe7d23e79c16186c547f96aa0e6a59 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 21 Dec 2025 11:54:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E9=87=8D=E6=9E=84=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BA=8B=E4=BB=B6=E4=B8=BA?= =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=B0=B1=E7=BB=AA=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 `ArchitectureInitializedEvent` 重命名为 `ArchitectureLifecycleReadyEvent`, 并在 `AbstractResourceFactorySystem` 中实现 `IArchitectureLifecycle` 接口, 使其在架构进入就绪阶段时注册并预加载资源。 --- GFramework.Core/architecture/Architecture.cs | 6 +++--- GFramework.Core/events/ArchitectureEvents.cs | 2 +- .../system/AbstractResourceFactorySystem.cs | 21 +++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs index c4c59c7..d9e79ad 100644 --- a/GFramework.Core/architecture/Architecture.cs +++ b/GFramework.Core/architecture/Architecture.cs @@ -106,10 +106,10 @@ public abstract class Architecture : IArchitecture where T : Architecture, // == Finalize == // 冻结IOC容器,不允许 anymore arch._mContainer.Freeze(); - arch.EnterPhase(ArchitecturePhase.Ready); - // 发送架构初始化完成事件 - arch.SendEvent(new ArchitectureEvents.ArchitectureInitializedEvent()); arch._mInited = true; + arch.EnterPhase(ArchitecturePhase.Ready); + // 发送架构生命周期就绪事件 + arch.SendEvent(new ArchitectureEvents.ArchitectureLifecycleReadyEvent()); return arch; }, LazyThreadSafetyMode.ExecutionAndPublication); diff --git a/GFramework.Core/events/ArchitectureEvents.cs b/GFramework.Core/events/ArchitectureEvents.cs index 251e2a2..7526d38 100644 --- a/GFramework.Core/events/ArchitectureEvents.cs +++ b/GFramework.Core/events/ArchitectureEvents.cs @@ -7,5 +7,5 @@ public static class ArchitectureEvents /// 架构初始化完成事件 /// 在所有 Model / System Init 执行完毕后派发 /// - public readonly struct ArchitectureInitializedEvent; + public readonly struct ArchitectureLifecycleReadyEvent; } \ No newline at end of file diff --git a/GFramework.Godot/system/AbstractResourceFactorySystem.cs b/GFramework.Godot/system/AbstractResourceFactorySystem.cs index 53a80f4..afbeab4 100644 --- a/GFramework.Godot/system/AbstractResourceFactorySystem.cs +++ b/GFramework.Godot/system/AbstractResourceFactorySystem.cs @@ -1,4 +1,5 @@ -using GFramework.Core.events; +using GFramework.Core.architecture; +using GFramework.Core.events; using GFramework.Core.extensions; using GFramework.Core.system; using GFramework.Game.assets; @@ -10,7 +11,7 @@ namespace GFramework.Godot.system; /// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。 /// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。 /// -public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem +public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitectureLifecycle { private ResourceFactory.Registry? _registry; private IResourceLoadSystem? _resourceLoadSystem; @@ -26,14 +27,22 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF _registry = new ResourceFactory.Registry(); _resourceLoadSystem = this.GetSystem(); _assetCatalogSystem = this.GetSystem(); - // 监听架构初始化事件 - this.RegisterEvent(_ => + } + + /// + /// 架构阶段回调,在架构就绪时注册和预加载资源 + /// + /// 当前架构阶段 + /// 架构实例 + public void OnPhase(ArchitecturePhase phase, IArchitecture arch) + { + if (phase == ArchitecturePhase.Ready) { // 注册资源 RegisterResources(); // 预加载所有资源 - _registry.PreloadAll(); - }); + _registry!.PreloadAll(); + } } ///