From 2cfa78b91dd884a7c2f0aa33ee24dad4fa689d96 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Wed, 31 Dec 2025 12:42:06 +0800
Subject: [PATCH] =?UTF-8?q?feat(architecture):=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=9E=B6=E6=9E=84=E9=98=B6=E6=AE=B5=E6=84=9F=E7=9F=A5=E8=83=BD?=
=?UTF-8?q?=E5=8A=9B=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 在AbstractModel和AbstractSystem中添加OnArchitecturePhase虚方法实现
- 修改Architecture类移除IArchitectureLifecycle接口和OnPhase方法
- 更新IModel和ISystem接口继承IArchitecturePhaseAware接口
- 修改AbstractResourceFactorySystem实现IArchitecturePhaseAware接口
- 在测试类TestModel和TestSystem中添加OnArchitecturePhase方法实现
- 在项目文件中添加对生成器相关目录的排除配置
- 将ArchitecturePhase枚举引入到相关文件中
---
GFramework.Core.Abstractions/model/IModel.cs | 5 +++--
GFramework.Core.Abstractions/system/ISystem.cs | 3 ++-
GFramework.Core.Tests/model/TestModel.cs | 5 +++++
GFramework.Core.Tests/system/TestSystem.cs | 5 +++++
GFramework.Core/architecture/Architecture.cs | 17 ++---------------
GFramework.Core/model/AbstractModel.cs | 9 +++++++++
GFramework.Core/system/AbstractSystem.cs | 9 +++++++++
.../assets/AbstractResourceFactorySystem.cs | 14 +++++++-------
GFramework.csproj | 12 ++++++++++++
9 files changed, 54 insertions(+), 25 deletions(-)
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 @@
+
+
+
+