diff --git a/GFramework.Core.Abstractions/model/IModel.cs b/GFramework.Core.Abstractions/model/IModel.cs index a456627..9fb2e52 100644 --- a/GFramework.Core.Abstractions/model/IModel.cs +++ b/GFramework.Core.Abstractions/model/IModel.cs @@ -1,11 +1,12 @@ -using GFramework.Core.Abstractions.rule; +using GFramework.Core.Abstractions.architecture; +using GFramework.Core.Abstractions.rule; namespace GFramework.Core.Abstractions.model; /// /// 模型接口,定义了模型的基本行为和功能 /// -public interface IModel : IContextAware +public interface IModel : IContextAware, IArchitecturePhaseAware { /// /// 初始化模型 diff --git a/GFramework.Core.Abstractions/system/ISystem.cs b/GFramework.Core.Abstractions/system/ISystem.cs index 1dbb3aa..ae2a3b2 100644 --- a/GFramework.Core.Abstractions/system/ISystem.cs +++ b/GFramework.Core.Abstractions/system/ISystem.cs @@ -1,3 +1,4 @@ +using GFramework.Core.Abstractions.architecture; using GFramework.Core.Abstractions.rule; namespace GFramework.Core.Abstractions.system; @@ -6,7 +7,7 @@ namespace GFramework.Core.Abstractions.system; /// 系统接口,定义了系统的基本行为和功能 /// 该接口继承了多个框架相关的接口,提供了系统初始化和销毁能力 /// -public interface ISystem : IContextAware +public interface ISystem : IContextAware, IArchitecturePhaseAware { /// /// 初始化系统 diff --git a/GFramework.Core.Tests/model/TestModel.cs b/GFramework.Core.Tests/model/TestModel.cs index 2cb560b..cc3dc37 100644 --- a/GFramework.Core.Tests/model/TestModel.cs +++ b/GFramework.Core.Tests/model/TestModel.cs @@ -1,4 +1,5 @@ using GFramework.Core.Abstractions.architecture; +using GFramework.Core.Abstractions.enums; using GFramework.Core.Abstractions.model; namespace GFramework.Core.Tests.model; @@ -32,4 +33,8 @@ public sealed class TestModel : IModel { return _context; } + + public void OnArchitecturePhase(ArchitecturePhase phase) + { + } } \ No newline at end of file diff --git a/GFramework.Core.Tests/system/TestSystem.cs b/GFramework.Core.Tests/system/TestSystem.cs index a0a0e88..3695324 100644 --- a/GFramework.Core.Tests/system/TestSystem.cs +++ b/GFramework.Core.Tests/system/TestSystem.cs @@ -1,4 +1,5 @@ using GFramework.Core.Abstractions.architecture; +using GFramework.Core.Abstractions.enums; using GFramework.Core.Abstractions.system; namespace GFramework.Core.Tests.system; @@ -56,4 +57,8 @@ public sealed class TestSystem : ISystem { Destroyed = true; } + + public void OnArchitecturePhase(ArchitecturePhase phase) + { + } } \ No newline at end of file diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs index efa0ea8..09a7097 100644 --- a/GFramework.Core/architecture/Architecture.cs +++ b/GFramework.Core/architecture/Architecture.cs @@ -20,7 +20,7 @@ public abstract class Architecture( IArchitectureServices? services = null, IArchitectureContext? context = null ) - : IArchitecture, IArchitectureLifecycle + : IArchitecture { /// /// 获取架构配置对象 @@ -80,19 +80,6 @@ public abstract class Architecture( #endregion - #region IArchitectureLifecycle Implementation - - /// - /// 处理架构阶段变更通知 - /// - /// 当前架构阶段 - /// 架构实例 - public virtual void OnPhase(ArchitecturePhase phase, IArchitecture architecture) - { - } - - #endregion - #region Fields and Properties /// @@ -362,7 +349,7 @@ public abstract class Architecture( { if (CurrentPhase >= ArchitecturePhase.Ready && !Configuration.Options.AllowLateRegistration) { - var errorMsg = "Cannot register system after Architecture is Ready"; + const string errorMsg = "Cannot register system after Architecture is Ready"; _logger.Error(errorMsg); throw new InvalidOperationException(errorMsg); } diff --git a/GFramework.Core/model/AbstractModel.cs b/GFramework.Core/model/AbstractModel.cs index 8f81fe4..8b0e4fb 100644 --- a/GFramework.Core/model/AbstractModel.cs +++ b/GFramework.Core/model/AbstractModel.cs @@ -1,4 +1,5 @@ using GFramework.Core.Abstractions.architecture; +using GFramework.Core.Abstractions.enums; using GFramework.Core.Abstractions.model; namespace GFramework.Core.model; @@ -31,6 +32,14 @@ public abstract class AbstractModel : IModel return _context; } + /// + /// 处理架构阶段事件的虚拟方法 + /// + /// 当前的架构阶段 + public virtual void OnArchitecturePhase(ArchitecturePhase phase) + { + } + /// /// 抽象初始化方法,由子类实现具体的初始化逻辑 diff --git a/GFramework.Core/system/AbstractSystem.cs b/GFramework.Core/system/AbstractSystem.cs index aab9b5a..5415d08 100644 --- a/GFramework.Core/system/AbstractSystem.cs +++ b/GFramework.Core/system/AbstractSystem.cs @@ -1,3 +1,4 @@ +using GFramework.Core.Abstractions.enums; using GFramework.Core.Abstractions.logging; using GFramework.Core.Abstractions.system; using GFramework.Core.rule; @@ -37,6 +38,14 @@ public abstract class AbstractSystem : ContextAwareBase, ISystem _logger.Info($"System destroyed: {GetType().Name}"); } + /// + /// 处理架构阶段事件的虚拟方法 + /// + /// 当前的架构阶段 + public virtual void OnArchitecturePhase(ArchitecturePhase phase) + { + } + /// /// 抽象初始化方法,由子类实现具体的初始化逻辑 /// diff --git a/GFramework.Godot/assets/AbstractResourceFactorySystem.cs b/GFramework.Godot/assets/AbstractResourceFactorySystem.cs index ec079b2..f986663 100644 --- a/GFramework.Godot/assets/AbstractResourceFactorySystem.cs +++ b/GFramework.Godot/assets/AbstractResourceFactorySystem.cs @@ -11,24 +11,23 @@ namespace GFramework.Godot.assets; /// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。 /// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。 /// -public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitectureLifecycle +public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitecturePhaseAware { private IAssetCatalogSystem? _assetCatalogSystem; private ResourceFactory.Registry? _registry; private IResourceLoadSystem? _resourceLoadSystem; + /// - /// 架构阶段回调,在架构就绪时注册和预加载资源 + /// 在架构阶段发生变化时执行相应的处理逻辑。 /// - /// 当前架构阶段 - /// 架构实例 - public void OnPhase(ArchitecturePhase phase, IArchitecture architecture) + /// 当前的架构阶段 + public void OnArchitecturePhase(ArchitecturePhase phase) { if (phase == ArchitecturePhase.Ready) { - // 注册资源 + // 在架构准备就绪阶段注册资源并预加载所有资源 RegisterResources(); - // 预加载所有资源 _registry!.PreloadAll(); } } @@ -45,6 +44,7 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF return _registry!.ResolveFactory(key); } + /// /// 根据资产目录映射信息获取资源工厂函数。 /// diff --git a/GFramework.csproj b/GFramework.csproj index 961552b..6c6de78 100644 --- a/GFramework.csproj +++ b/GFramework.csproj @@ -47,6 +47,10 @@ + + + + @@ -77,6 +81,10 @@ + + + + @@ -93,6 +101,10 @@ + + + +