From 017870421ee3c4ede773cb813a13d6ae26644f05 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Fri, 26 Dec 2025 13:50:14 +0800
Subject: [PATCH] =?UTF-8?q?style(csharp):=20=E7=BB=9F=E4=B8=80=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96=E8=A7=84=E8=8C=83=E5=B9=B6?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B9=E6=B3=95=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 调整注释格式统一使用4个空格缩进
- 重新排列字段声明顺序提升代码可读性
- 将简单属性访问器改为表达式主体语法
- 优化AudioManagerSystem中音量设置逻辑
- 移除AbstractAssetCatalogSystem中多余空行
- 重构日志类中方法实现为表达式主体形式
- 统一空行分隔符保持代码结构一致性
- 优化方法内部逻辑表达式简化代码
- [no tag]
---
GFramework.Core/architecture/Architecture.cs | 53 +-
.../architecture/ArchitectureConfiguration.cs | 30 +-
.../architecture/ArchitectureConstants.cs | 3 +-
.../architecture/ArchitectureContext.cs | 2 +-
.../architecture/ArchitectureOptions.cs | 14 +-
.../architecture/ArchitecturePhase.cs | 36 +-
.../architecture/ArchitectureRuntime.cs | 32 +-
.../architecture/ArchitectureServices.cs | 5 +-
GFramework.Core/architecture/IArchitecture.cs | 48 +-
.../IArchitectureConfiguration.cs | 10 +-
.../architecture/IArchitectureContext.cs | 24 +-
.../architecture/IArchitectureExtensible.cs | 11 +-
.../architecture/IArchitectureLifecycle.cs | 7 +-
.../architecture/IArchitectureModule.cs | 11 +-
.../architecture/IArchitecturePhaseAware.cs | 7 +-
.../architecture/IArchitectureRuntime.cs | 18 +-
.../architecture/IArchitectureServices.cs | 10 +-
.../architecture/IAsyncInitializable.cs | 6 +-
GFramework.Core/command/ICommand.cs | 4 +-
.../constants/GFrameworkConstants.cs | 6 +-
GFramework.Core/events/ArchitectureEvents.cs | 20 +-
GFramework.Core/events/ITypeEventSystem.cs | 12 +-
GFramework.Core/events/TypeEventSystem.cs | 25 +-
GFramework.Core/ioc/IIocContainer.cs | 32 +-
GFramework.Core/ioc/IocContainer.cs | 50 +-
GFramework.Core/logging/AbstractLogger.cs | 352 +++++---
GFramework.Core/logging/ConsoleLogger.cs | 47 +-
.../logging/ConsoleLoggerFactory.cs | 6 +-
GFramework.Core/logging/ILogger.cs | 134 +--
GFramework.Core/logging/ILoggerFactory.cs | 4 +-
GFramework.Core/logging/LogLevel.cs | 21 +-
GFramework.Core/logging/NoopLogger.cs | 7 +-
GFramework.Core/logging/NoopLoggerFactory.cs | 6 +-
GFramework.Core/logging/README.md | 21 +-
GFramework.Core/model/AbstractModel.cs | 16 +-
GFramework.Core/model/IModel.cs | 6 +-
GFramework.Core/query/AbstractQuery.cs | 4 +-
GFramework.Core/query/IQuery.cs | 2 +-
GFramework.Core/rule/ContextAwareBase.cs | 14 +-
GFramework.Core/rule/IContextAware.cs | 6 +-
GFramework.Core/rule/ILogAware.cs | 6 +-
GFramework.Core/system/ISystem.cs | 2 +-
.../utility/AbstractContextUtility.cs | 6 +-
GFramework.Core/utility/IContextUtility.cs | 11 +-
GFramework.Game/GFramework.Game.csproj | 2 +-
.../assets/AbstractAssetCatalogSystem.cs | 81 +-
GFramework.Game/assets/AssetCatalog.cs | 24 +-
GFramework.Game/assets/IAssetCatalogSystem.cs | 27 +-
.../assets/IResourceFactorySystem.cs | 11 +-
GFramework.Game/assets/ResourceFactory.cs | 60 +-
.../logging/GodotLogAttribute.cs | 6 +-
.../logging/Diagnostic.cs | 44 -
.../logging/GodotLoggerDiagnostic.cs | 44 +
.../logging/GodotLoggerGenerator.cs | 10 +-
GFramework.Godot/GFramework.Godot.csproj | 2 +-
.../architecture/AbstractArchitecture.cs | 68 +-
.../architecture/AbstractGodotModule.cs | 24 +-
.../architecture/ArchitectureAnchor.cs | 18 +-
GFramework.Godot/architecture/IGodotModule.cs | 8 +-
.../assets/AbstractResourceFactorySystem.cs | 64 +-
.../assets/IResourceLoadSystem.cs | 30 +-
GFramework.Godot/assets/ResourceLoadSystem.cs | 141 +--
GFramework.Godot/extensions/NodeExtensions.cs | 6 +-
GFramework.Godot/logging/GodotLogger.cs | 9 +-
.../logging/GodotLoggerFactory.cs | 8 +-
.../system/AbstractAudioManagerSystem.cs | 842 +++++++++---------
.../system/IAudioManagerSystem.cs | 104 +--
...amework.SourceGenerators.Attributes.csproj | 2 +-
.../enums/EnumExtensionsAttribute.cs | 27 +-
.../logging/LogAttribute.cs | 4 +-
.../logging/Diagnostic.cs | 37 -
.../logging/LoggerDiagnostic.cs | 37 +
.../logging/LoggerGenerator.cs | 12 +-
GFramework.csproj | 24 +-
74 files changed, 1519 insertions(+), 1404 deletions(-)
delete mode 100644 GFramework.Godot.SourceGenerators/logging/Diagnostic.cs
create mode 100644 GFramework.Godot.SourceGenerators/logging/GodotLoggerDiagnostic.cs
delete mode 100644 GFramework.SourceGenerators/logging/Diagnostic.cs
create mode 100644 GFramework.SourceGenerators/logging/LoggerDiagnostic.cs
diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs
index 8d24f6d..5a55424 100644
--- a/GFramework.Core/architecture/Architecture.cs
+++ b/GFramework.Core/architecture/Architecture.cs
@@ -8,9 +8,9 @@ using GFramework.Core.utility;
namespace GFramework.Core.architecture;
///
-/// 架构基类,提供系统、模型、工具等组件的注册与管理功能。
-/// 专注于生命周期管理、初始化流程控制和架构阶段转换。
-/// 不直接提供业务操作方法,业务操作通过 ArchitectureRuntime 提供。
+/// 架构基类,提供系统、模型、工具等组件的注册与管理功能。
+/// 专注于生命周期管理、初始化流程控制和架构阶段转换。
+/// 不直接提供业务操作方法,业务操作通过 ArchitectureRuntime 提供。
///
public abstract class Architecture(
IArchitectureConfiguration? configuration = null,
@@ -20,49 +20,49 @@ public abstract class Architecture(
: IArchitecture, IArchitectureLifecycle
{
///
- /// 获取架构配置对象
+ /// 获取架构配置对象
///
///
- /// 返回一个IArchitectureConfiguration接口的实例,默认为DefaultArchitectureConfiguration类型
+ /// 返回一个IArchitectureConfiguration接口的实例,默认为DefaultArchitectureConfiguration类型
///
private IArchitectureConfiguration Configuration { get; } = configuration ?? new ArchitectureConfiguration();
///
- /// 获取架构服务对象
+ /// 获取架构服务对象
///
///
- /// 返回一个IArchitectureServices接口的实例,默认为DefaultArchitectureServices类型
+ /// 返回一个IArchitectureServices接口的实例,默认为DefaultArchitectureServices类型
///
private IArchitectureServices Services { get; } = services ?? new ArchitectureServices();
///
- /// 获取依赖注入容器
+ /// 获取依赖注入容器
///
///
- /// 通过Services属性获取的IArchitectureServices中的Container属性
+ /// 通过Services属性获取的IArchitectureServices中的Container属性
///
private IIocContainer Container => Services.Container;
///
- /// 获取类型事件系统
+ /// 获取类型事件系统
///
///
- /// 通过Services属性获取的IArchitectureServices中的TypeEventSystem属性
+ /// 通过Services属性获取的IArchitectureServices中的TypeEventSystem属性
///
private ITypeEventSystem TypeEventSystem => Services.TypeEventSystem;
///
- /// 获取架构运行时实例
+ /// 获取架构运行时实例
///
///
- /// 统一的操作入口,负责命令、查询、事件的执行
+ /// 统一的操作入口,负责命令、查询、事件的执行
///
public IArchitectureRuntime Runtime { get; private set; } = null!;
#region Module Management
///
- /// 安装架构模块
+ /// 安装架构模块
///
/// 要安装的模块
public void InstallModule(IArchitectureModule module)
@@ -80,7 +80,7 @@ public abstract class Architecture(
#region IArchitectureLifecycle Implementation
///
- /// 处理架构阶段变更通知
+ /// 处理架构阶段变更通知
///
/// 当前架构阶段
/// 架构实例
@@ -123,7 +123,7 @@ public abstract class Architecture(
private ArchitecturePhase CurrentPhase { get; set; }
///
- /// 日志记录器实例,用于记录应用程序的运行日志
+ /// 日志记录器实例,用于记录应用程序的运行日志
///
private ILogger _logger = null!;
@@ -136,7 +136,7 @@ public abstract class Architecture(
#region Lifecycle Management
///
- /// 进入指定的架构阶段,并执行相应的生命周期管理操作
+ /// 进入指定的架构阶段,并执行相应的生命周期管理操作
///
/// 要进入的下一个架构阶段
/// 当阶段转换不被允许时抛出异常
@@ -156,10 +156,7 @@ public abstract class Architecture(
var previousPhase = CurrentPhase;
CurrentPhase = next;
- if (previousPhase != next)
- {
- logger.Info($"Architecture phase changed: {previousPhase} -> {next}");
- }
+ if (previousPhase != next) logger.Info($"Architecture phase changed: {previousPhase} -> {next}");
NotifyPhase(next);
@@ -172,7 +169,7 @@ public abstract class Architecture(
}
///
- /// 通知所有生命周期钩子当前阶段变更
+ /// 通知所有生命周期钩子当前阶段变更
///
/// 当前架构阶段
private void NotifyPhase(ArchitecturePhase phase)
@@ -182,7 +179,7 @@ public abstract class Architecture(
}
///
- /// 注册生命周期钩子
+ /// 注册生命周期钩子
///
/// 生命周期钩子实例
public void RegisterLifecycleHook(IArchitectureLifecycle hook)
@@ -200,11 +197,11 @@ public abstract class Architecture(
protected abstract void Init();
///
- /// 销毁架构并清理所有系统资源
+ /// 销毁架构并清理所有系统资源
///
///
- /// 此函数负责有序地销毁架构中的所有系统组件,并发送相应的生命周期事件。
- /// 函数会确保只执行一次销毁操作,避免重复销毁。
+ /// 此函数负责有序地销毁架构中的所有系统组件,并发送相应的生命周期事件。
+ /// 函数会确保只执行一次销毁操作,避免重复销毁。
///
public virtual void Destroy()
{
@@ -368,7 +365,9 @@ public abstract class Architecture(
Container.RegisterPlurality(system);
_allSystems.Add(system);
if (!_mInited)
+ {
_mSystems.Add(system);
+ }
else
{
_logger.Debug($"Immediately initializing system: {typeof(TSystem).Name}");
@@ -400,7 +399,9 @@ public abstract class Architecture(
Container.RegisterPlurality(model);
if (!_mInited)
+ {
_mModels.Add(model);
+ }
else
{
_logger.Debug($"Immediately initializing model: {typeof(TModel).Name}");
diff --git a/GFramework.Core/architecture/ArchitectureConfiguration.cs b/GFramework.Core/architecture/ArchitectureConfiguration.cs
index f61335a..89f7f89 100644
--- a/GFramework.Core/architecture/ArchitectureConfiguration.cs
+++ b/GFramework.Core/architecture/ArchitectureConfiguration.cs
@@ -3,26 +3,26 @@
namespace GFramework.Core.architecture;
///
-/// 默认架构配置类,实现IArchitectureConfiguration接口
-/// 提供日志工厂、日志级别和架构选项的默认配置
+/// 默认架构配置类,实现IArchitectureConfiguration接口
+/// 提供日志工厂、日志级别和架构选项的默认配置
///
-public class ArchitectureConfiguration: IArchitectureConfiguration
+public class ArchitectureConfiguration : IArchitectureConfiguration
{
///
- /// 获取或设置日志工厂实例
- /// 默认使用控制台日志工厂
- ///
- public ILoggerFactory LoggerFactory { get; set; } = new ConsoleLoggerFactory();
-
- ///
- /// 获取或设置日志级别
- /// 默认设置为Info级别
+ /// 获取或设置日志级别
+ /// 默认设置为Info级别
///
public LogLevel LogLevel { get; set; } = LogLevel.Info;
-
+
///
- /// 获取或设置架构选项
- /// 默认创建新的ArchitectureOptions实例
+ /// 获取或设置日志工厂实例
+ /// 默认使用控制台日志工厂
+ ///
+ public ILoggerFactory LoggerFactory { get; set; } = new ConsoleLoggerFactory();
+
+ ///
+ /// 获取或设置架构选项
+ /// 默认创建新的ArchitectureOptions实例
///
public ArchitectureOptions Options { get; set; } = new();
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/ArchitectureConstants.cs b/GFramework.Core/architecture/ArchitectureConstants.cs
index 784b15d..19e71bc 100644
--- a/GFramework.Core/architecture/ArchitectureConstants.cs
+++ b/GFramework.Core/architecture/ArchitectureConstants.cs
@@ -1,5 +1,4 @@
-
-using System.Collections.Immutable;
+using System.Collections.Immutable;
namespace GFramework.Core.architecture;
diff --git a/GFramework.Core/architecture/ArchitectureContext.cs b/GFramework.Core/architecture/ArchitectureContext.cs
index e907ca6..cb5265b 100644
--- a/GFramework.Core/architecture/ArchitectureContext.cs
+++ b/GFramework.Core/architecture/ArchitectureContext.cs
@@ -10,7 +10,7 @@ using GFramework.Core.utility;
namespace GFramework.Core.architecture;
///
-/// 架构上下文类,提供对系统、模型、工具等组件的访问以及命令、查询、事件的执行管理
+/// 架构上下文类,提供对系统、模型、工具等组件的访问以及命令、查询、事件的执行管理
///
public class ArchitectureContext(
IIocContainer container,
diff --git a/GFramework.Core/architecture/ArchitectureOptions.cs b/GFramework.Core/architecture/ArchitectureOptions.cs
index 9baaa1c..8d5c916 100644
--- a/GFramework.Core/architecture/ArchitectureOptions.cs
+++ b/GFramework.Core/architecture/ArchitectureOptions.cs
@@ -1,7 +1,7 @@
namespace GFramework.Core.architecture;
///
-/// 架构选项配置类,用于定义架构行为的相关配置选项
+/// 架构选项配置类,用于定义架构行为的相关配置选项
///
public sealed class ArchitectureOptions(
bool strictPhaseValidation = true,
@@ -9,12 +9,12 @@ public sealed class ArchitectureOptions(
)
{
///
- /// 严格阶段验证开关,当设置为true时启用严格的阶段验证机制
- ///
- public bool StrictPhaseValidation = strictPhaseValidation;
-
- ///
- /// 允许延迟注册开关,当设置为true时允许在初始化完成后进行组件注册
+ /// 允许延迟注册开关,当设置为true时允许在初始化完成后进行组件注册
///
public bool AllowLateRegistration = allowLateRegistration;
+
+ ///
+ /// 严格阶段验证开关,当设置为true时启用严格的阶段验证机制
+ ///
+ public bool StrictPhaseValidation = strictPhaseValidation;
}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/ArchitecturePhase.cs b/GFramework.Core/architecture/ArchitecturePhase.cs
index 052ea91..ef93dfa 100644
--- a/GFramework.Core/architecture/ArchitecturePhase.cs
+++ b/GFramework.Core/architecture/ArchitecturePhase.cs
@@ -1,49 +1,51 @@
namespace GFramework.Core.architecture;
///
-/// 架构阶段枚举,定义了系统架构初始化和运行过程中的各个关键阶段
+/// 架构阶段枚举,定义了系统架构初始化和运行过程中的各个关键阶段
///
///
-/// 该枚举用于标记和控制系统架构组件的生命周期,确保在正确的时机执行相应的初始化和处理逻辑。
-/// 各个阶段按照时间顺序排列,从创建到准备就绪的完整流程。
+/// 该枚举用于标记和控制系统架构组件的生命周期,确保在正确的时机执行相应的初始化和处理逻辑。
+/// 各个阶段按照时间顺序排列,从创建到准备就绪的完整流程。
///
public enum ArchitecturePhase
{
///
- /// 无效阶段,表示未定义的阶段
+ /// 无效阶段,表示未定义的阶段
///
None = 0,
+
///
- /// 模型初始化之前阶段
+ /// 模型初始化之前阶段
///
BeforeModelInit,
-
+
///
- /// 模型初始化之后阶段
+ /// 模型初始化之后阶段
///
AfterModelInit,
-
+
///
- /// 系统初始化之前阶段
+ /// 系统初始化之前阶段
///
BeforeSystemInit,
-
+
///
- /// 系统初始化之后阶段
+ /// 系统初始化之后阶段
///
AfterSystemInit,
-
+
///
- /// 就绪阶段,完成冻结和事件处理后的最终状态
+ /// 就绪阶段,完成冻结和事件处理后的最终状态
///
Ready,
+
///
- /// 正在销毁中 暂时不使用
+ /// 正在销毁中 暂时不使用
///
Destroying,
+
///
- /// 已销毁 暂时不使用
+ /// 已销毁 暂时不使用
///
Destroyed
-
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/ArchitectureRuntime.cs b/GFramework.Core/architecture/ArchitectureRuntime.cs
index 6ee87bc..b5ac076 100644
--- a/GFramework.Core/architecture/ArchitectureRuntime.cs
+++ b/GFramework.Core/architecture/ArchitectureRuntime.cs
@@ -5,12 +5,27 @@ using GFramework.Core.query;
namespace GFramework.Core.architecture;
///
-/// 架构运行时默认实现,委托 ArchitectureContext 执行具体操作
+/// 架构运行时默认实现,委托 ArchitectureContext 执行具体操作
///
public class ArchitectureRuntime(IArchitectureContext context) : IArchitectureRuntime
{
private readonly IArchitectureContext _context = context ?? throw new ArgumentNullException(nameof(context));
+ #region Query Execution
+
+ ///
+ /// 发起一次查询请求并获得其结果
+ ///
+ /// 查询结果的数据类型
+ /// 要发起的查询对象
+ /// 查询得到的结果数据
+ public TResult SendQuery(IQuery query)
+ {
+ return _context.SendQuery(query);
+ }
+
+ #endregion
+
#region Command Execution
///
@@ -36,21 +51,6 @@ public class ArchitectureRuntime(IArchitectureContext context) : IArchitectureRu
#endregion
- #region Query Execution
-
- ///
- /// 发起一次查询请求并获得其结果
- ///
- /// 查询结果的数据类型
- /// 要发起的查询对象
- /// 查询得到的结果数据
- public TResult SendQuery(IQuery query)
- {
- return _context.SendQuery(query);
- }
-
- #endregion
-
#region Event Management
///
diff --git a/GFramework.Core/architecture/ArchitectureServices.cs b/GFramework.Core/architecture/ArchitectureServices.cs
index 09a8412..804b657 100644
--- a/GFramework.Core/architecture/ArchitectureServices.cs
+++ b/GFramework.Core/architecture/ArchitectureServices.cs
@@ -1,10 +1,9 @@
-
-using GFramework.Core.events;
+using GFramework.Core.events;
using GFramework.Core.ioc;
namespace GFramework.Core.architecture;
-public class ArchitectureServices: IArchitectureServices
+public class ArchitectureServices : IArchitectureServices
{
public IIocContainer Container { get; } = new IocContainer();
public ITypeEventSystem TypeEventSystem { get; } = new TypeEventSystem();
diff --git a/GFramework.Core/architecture/IArchitecture.cs b/GFramework.Core/architecture/IArchitecture.cs
index 33818db..a501457 100644
--- a/GFramework.Core/architecture/IArchitecture.cs
+++ b/GFramework.Core/architecture/IArchitecture.cs
@@ -1,8 +1,4 @@
-using GFramework.Core.architecture;
-using GFramework.Core.command;
-using GFramework.Core.events;
-using GFramework.Core.model;
-using GFramework.Core.query;
+using GFramework.Core.model;
using GFramework.Core.system;
using GFramework.Core.utility;
@@ -12,64 +8,64 @@ namespace GFramework.Core.architecture;
/// 架构接口,专注于生命周期管理,包括系统、模型、工具的注册和获取
/// 业务操作通过 ArchitectureRuntime 提供
///
-public interface IArchitecture: IAsyncInitializable
+public interface IArchitecture : IAsyncInitializable
{
///
- /// 初始化方法,用于执行对象的初始化操作
+ /// 获取架构上下文
+ ///
+ IArchitectureContext Context { get; }
+
+ ///
+ /// 获取架构运行时实例
+ ///
+ IArchitectureRuntime Runtime { get; }
+
+ ///
+ /// 初始化方法,用于执行对象的初始化操作
///
///
- /// 该方法通常用于设置初始状态、初始化成员变量或执行必要的预处理操作
+ /// 该方法通常用于设置初始状态、初始化成员变量或执行必要的预处理操作
///
void Initialize();
-
+
///
- /// 销毁方法,用于执行对象的清理和销毁操作
+ /// 销毁方法,用于执行对象的清理和销毁操作
///
///
- /// 该方法通常用于释放资源、清理内存或执行必要的清理操作
+ /// 该方法通常用于释放资源、清理内存或执行必要的清理操作
///
void Destroy();
///
- /// 注册系统实例到架构中
+ /// 注册系统实例到架构中
///
/// 系统类型,必须实现ISystem接口
/// 要注册的系统实例
void RegisterSystem(T system) where T : ISystem;
///
- /// 注册模型实例到架构中
+ /// 注册模型实例到架构中
///
/// 模型类型,必须实现IModel接口
/// 要注册的模型实例
void RegisterModel(T model) where T : IModel;
///
- /// 注册工具实例到架构中
+ /// 注册工具实例到架构中
///
/// 工具类型,必须实现IUtility接口
/// 要注册的工具实例
void RegisterUtility(T utility) where T : IUtility;
///
- /// 安装架构模块
+ /// 安装架构模块
///
/// 要安装的模块
void InstallModule(IArchitectureModule module);
///
- /// 注册生命周期钩子
+ /// 注册生命周期钩子
///
/// 生命周期钩子实例
void RegisterLifecycleHook(IArchitectureLifecycle hook);
-
- ///
- /// 获取架构上下文
- ///
- IArchitectureContext Context { get; }
-
- ///
- /// 获取架构运行时实例
- ///
- IArchitectureRuntime Runtime { get; }
}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitectureConfiguration.cs b/GFramework.Core/architecture/IArchitectureConfiguration.cs
index 9fbe6a5..cf4bd3d 100644
--- a/GFramework.Core/architecture/IArchitectureConfiguration.cs
+++ b/GFramework.Core/architecture/IArchitectureConfiguration.cs
@@ -3,17 +3,17 @@
namespace GFramework.Core.architecture;
///
-/// 定义架构配置的接口,提供日志工厂、日志级别和架构选项的配置功能
+/// 定义架构配置的接口,提供日志工厂、日志级别和架构选项的配置功能
///
public interface IArchitectureConfiguration
{
///
- /// 获取或设置日志工厂,用于创建日志记录器实例
+ /// 获取或设置日志工厂,用于创建日志记录器实例
///
ILoggerFactory LoggerFactory { get; set; }
-
+
///
- /// 获取或设置架构选项,包含架构相关的配置参数
+ /// 获取或设置架构选项,包含架构相关的配置参数
///
ArchitectureOptions Options { get; set; }
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitectureContext.cs b/GFramework.Core/architecture/IArchitectureContext.cs
index 2a2fa88..ae589d6 100644
--- a/GFramework.Core/architecture/IArchitectureContext.cs
+++ b/GFramework.Core/architecture/IArchitectureContext.cs
@@ -9,44 +9,44 @@ using GFramework.Core.utility;
namespace GFramework.Core.architecture;
///
-/// 架构上下文接口,提供对系统、模型、工具类的访问以及命令、查询、事件的发送和注册功能
+/// 架构上下文接口,提供对系统、模型、工具类的访问以及命令、查询、事件的发送和注册功能
///
public interface IArchitectureContext
{
///
- /// 获取日志工厂
+ /// 获取日志工厂
///
ILoggerFactory LoggerFactory { get; }
///
- /// 获取指定类型的系统实例
+ /// 获取指定类型的系统实例
///
/// 系统类型,必须继承自ISystem接口
/// 系统实例,如果不存在则返回null
TSystem? GetSystem() where TSystem : class, ISystem;
///
- /// 获取指定类型的模型实例
+ /// 获取指定类型的模型实例
///
/// 模型类型,必须继承自IModel接口
/// 模型实例,如果不存在则返回null
TModel? GetModel() where TModel : class, IModel;
///
- /// 获取指定类型的工具类实例
+ /// 获取指定类型的工具类实例
///
/// 工具类类型,必须继承自IUtility接口
/// 工具类实例,如果不存在则返回null
TUtility? GetUtility() where TUtility : class, IUtility;
///
- /// 发送一个命令
+ /// 发送一个命令
///
/// 要发送的命令
void SendCommand(ICommand command);
///
- /// 发送一个带返回值的命令
+ /// 发送一个带返回值的命令
///
/// 命令执行结果类型
/// 要发送的命令
@@ -54,7 +54,7 @@ public interface IArchitectureContext
TResult SendCommand(ICommand command);
///
- /// 发送一个查询请求
+ /// 发送一个查询请求
///
/// 查询结果类型
/// 要发送的查询
@@ -62,20 +62,20 @@ public interface IArchitectureContext
TResult SendQuery(IQuery query);
///
- /// 发送一个事件
+ /// 发送一个事件
///
/// 事件类型,必须具有无参构造函数
void SendEvent() where TEvent : new();
///
- /// 发送一个带参数的事件
+ /// 发送一个带参数的事件
///
/// 事件类型
/// 事件参数
void SendEvent(TEvent e) where TEvent : class;
///
- /// 注册事件处理器
+ /// 注册事件处理器
///
/// 事件类型
/// 事件处理委托
@@ -83,7 +83,7 @@ public interface IArchitectureContext
IUnRegister RegisterEvent(Action handler);
///
- /// 取消注册事件监听器
+ /// 取消注册事件监听器
///
/// 事件类型
/// 要取消注册的事件回调方法
diff --git a/GFramework.Core/architecture/IArchitectureExtensible.cs b/GFramework.Core/architecture/IArchitectureExtensible.cs
index 87545af..1fd93a7 100644
--- a/GFramework.Core/architecture/IArchitectureExtensible.cs
+++ b/GFramework.Core/architecture/IArchitectureExtensible.cs
@@ -1,20 +1,19 @@
namespace GFramework.Core.architecture;
///
-/// 可扩展架构接口,继承自IArchitecture接口,提供模块安装和生命周期钩子注册功能
+/// 可扩展架构接口,继承自IArchitecture接口,提供模块安装和生命周期钩子注册功能
///
public interface IArchitectureExtensible : IArchitecture
{
///
- /// 安装架构模块
+ /// 安装架构模块
///
/// 要安装的架构模块实例
void InstallModule(IArchitectureModule module);
-
+
///
- /// 注册架构生命周期钩子
+ /// 注册架构生命周期钩子
///
/// 要注册的架构生命周期钩子实例
void RegisterLifecycleHook(IArchitectureLifecycle hook);
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitectureLifecycle.cs b/GFramework.Core/architecture/IArchitectureLifecycle.cs
index 370d608..97cc324 100644
--- a/GFramework.Core/architecture/IArchitectureLifecycle.cs
+++ b/GFramework.Core/architecture/IArchitectureLifecycle.cs
@@ -1,15 +1,14 @@
namespace GFramework.Core.architecture;
///
-/// 架构生命周期接口,定义了架构在不同阶段的回调方法
+/// 架构生命周期接口,定义了架构在不同阶段的回调方法
///
public interface IArchitectureLifecycle
{
///
- /// 当架构进入指定阶段时触发的回调方法
+ /// 当架构进入指定阶段时触发的回调方法
///
/// 当前的架构阶段
/// 相关的架构实例
void OnPhase(ArchitecturePhase phase, IArchitecture architecture);
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitectureModule.cs b/GFramework.Core/architecture/IArchitectureModule.cs
index 8c2bc4c..273cc14 100644
--- a/GFramework.Core/architecture/IArchitectureModule.cs
+++ b/GFramework.Core/architecture/IArchitectureModule.cs
@@ -1,15 +1,14 @@
-
-namespace GFramework.Core.architecture;
+namespace GFramework.Core.architecture;
///
-/// 架构模块接口,继承自架构生命周期接口。
-/// 定义了模块安装到架构中的标准方法。
+/// 架构模块接口,继承自架构生命周期接口。
+/// 定义了模块安装到架构中的标准方法。
///
public interface IArchitectureModule : IArchitectureLifecycle, IArchitecturePhaseAware
{
///
- /// 将当前模块安装到指定的架构中。
+ /// 将当前模块安装到指定的架构中。
///
/// 要安装模块的目标架构实例。
void Install(IArchitecture architecture);
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitecturePhaseAware.cs b/GFramework.Core/architecture/IArchitecturePhaseAware.cs
index 42467e6..557fd79 100644
--- a/GFramework.Core/architecture/IArchitecturePhaseAware.cs
+++ b/GFramework.Core/architecture/IArchitecturePhaseAware.cs
@@ -1,14 +1,13 @@
namespace GFramework.Core.architecture;
///
-/// 定义架构阶段感知接口,用于在架构的不同阶段执行相应的逻辑
+/// 定义架构阶段感知接口,用于在架构的不同阶段执行相应的逻辑
///
public interface IArchitecturePhaseAware
{
///
- /// 当架构进入指定阶段时触发的回调方法
+ /// 当架构进入指定阶段时触发的回调方法
///
/// 架构阶段枚举值,表示当前所处的架构阶段
void OnArchitecturePhase(ArchitecturePhase phase);
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IArchitectureRuntime.cs b/GFramework.Core/architecture/IArchitectureRuntime.cs
index 37ccb67..134da12 100644
--- a/GFramework.Core/architecture/IArchitectureRuntime.cs
+++ b/GFramework.Core/architecture/IArchitectureRuntime.cs
@@ -5,20 +5,20 @@ using GFramework.Core.query;
namespace GFramework.Core.architecture;
///
-/// 架构运行时接口,提供统一的命令、查询、事件操作入口
-/// 负责委托 ArchitectureContext 的能力执行具体操作
+/// 架构运行时接口,提供统一的命令、查询、事件操作入口
+/// 负责委托 ArchitectureContext 的能力执行具体操作
///
public interface IArchitectureRuntime
{
///
- /// 发送并执行指定的命令
+ /// 发送并执行指定的命令
///
/// 命令类型,必须实现ICommand接口
/// 要执行的命令实例
void SendCommand(T command) where T : ICommand;
///
- /// 发送并执行带有返回值的命令
+ /// 发送并执行带有返回值的命令
///
/// 命令执行结果的类型
/// 要执行的命令实例
@@ -26,7 +26,7 @@ public interface IArchitectureRuntime
TResult SendCommand(ICommand command);
///
- /// 发送并执行查询操作
+ /// 发送并执行查询操作
///
/// 查询结果的类型
/// 要执行的查询实例
@@ -34,20 +34,20 @@ public interface IArchitectureRuntime
TResult SendQuery(IQuery query);
///
- /// 发送无参事件
+ /// 发送无参事件
///
/// 事件类型,必须具有无参构造函数
void SendEvent() where TEvent : new();
///
- /// 发送指定的事件实例
+ /// 发送指定的事件实例
///
/// 事件类型
/// 要发送的事件实例
void SendEvent(TEvent e) where TEvent : class;
///
- /// 注册事件监听器
+ /// 注册事件监听器
///
/// 事件类型
/// 事件触发时的回调方法
@@ -55,7 +55,7 @@ public interface IArchitectureRuntime
IUnRegister RegisterEvent(Action onEvent);
///
- /// 取消注册事件监听器
+ /// 取消注册事件监听器
///
/// 事件类型
/// 要取消注册的事件回调方法
diff --git a/GFramework.Core/architecture/IArchitectureServices.cs b/GFramework.Core/architecture/IArchitectureServices.cs
index 13f2fd5..fe72e56 100644
--- a/GFramework.Core/architecture/IArchitectureServices.cs
+++ b/GFramework.Core/architecture/IArchitectureServices.cs
@@ -4,19 +4,19 @@ using GFramework.Core.ioc;
namespace GFramework.Core.architecture;
///
-/// 架构服务接口,定义了框架核心架构所需的服务组件
+/// 架构服务接口,定义了框架核心架构所需的服务组件
///
public interface IArchitectureServices
{
///
- /// 获取依赖注入容器
+ /// 获取依赖注入容器
///
/// IIocContainer类型的依赖注入容器实例
IIocContainer Container { get; }
-
+
///
- /// 获取类型事件系统
+ /// 获取类型事件系统
///
/// ITypeEventSystem类型的事件系统实例
ITypeEventSystem TypeEventSystem { get; }
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/architecture/IAsyncInitializable.cs b/GFramework.Core/architecture/IAsyncInitializable.cs
index 5f71077..03db994 100644
--- a/GFramework.Core/architecture/IAsyncInitializable.cs
+++ b/GFramework.Core/architecture/IAsyncInitializable.cs
@@ -1,13 +1,13 @@
namespace GFramework.Core.architecture;
///
-/// 定义异步初始化接口,用于需要异步初始化的组件或服务
+/// 定义异步初始化接口,用于需要异步初始化的组件或服务
///
public interface IAsyncInitializable
{
///
- /// 异步初始化方法,用于执行组件或服务的异步初始化逻辑
+ /// 异步初始化方法,用于执行组件或服务的异步初始化逻辑
///
/// 表示异步初始化操作的Task
Task InitializeAsync();
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/command/ICommand.cs b/GFramework.Core/command/ICommand.cs
index 3e37b03..b4c2214 100644
--- a/GFramework.Core/command/ICommand.cs
+++ b/GFramework.Core/command/ICommand.cs
@@ -6,7 +6,7 @@ namespace GFramework.Core.command;
/// 命令接口,定义了无返回值命令的基本契约
/// 该接口继承了多个框架能力接口,使命令可以访问架构、系统、模型、工具,并能够发送事件、命令和查询
///
-public interface ICommand: IContextAware
+public interface ICommand : IContextAware
{
///
/// 执行命令的核心方法
@@ -20,7 +20,7 @@ public interface ICommand: IContextAware
/// 该接口继承了多个框架能力接口,使命令可以访问架构、系统、模型、工具,并能够发送事件、命令和查询
///
/// 命令执行后返回的结果类型
-public interface ICommand: IContextAware
+public interface ICommand : IContextAware
{
///
/// 执行命令的核心方法
diff --git a/GFramework.Core/constants/GFrameworkConstants.cs b/GFramework.Core/constants/GFrameworkConstants.cs
index ef0e309..b00301b 100644
--- a/GFramework.Core/constants/GFrameworkConstants.cs
+++ b/GFramework.Core/constants/GFrameworkConstants.cs
@@ -1,12 +1,12 @@
namespace GFramework.Core.constants;
///
-/// GFramework框架常量定义类
+/// GFramework框架常量定义类
///
public static class GFrameworkConstants
{
///
- /// 框架名称常量
+ /// 框架名称常量
///
public const string FrameworkName = "GFramework";
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/events/ArchitectureEvents.cs b/GFramework.Core/events/ArchitectureEvents.cs
index d40b9fb..8a77c03 100644
--- a/GFramework.Core/events/ArchitectureEvents.cs
+++ b/GFramework.Core/events/ArchitectureEvents.cs
@@ -1,25 +1,25 @@
namespace GFramework.Core.events;
///
-/// 架构事件定义类,包含应用程序架构生命周期相关的事件结构体
+/// 架构事件定义类,包含应用程序架构生命周期相关的事件结构体
///
public static class ArchitectureEvents
{
///
- /// 架构生命周期准备就绪事件
- /// 当架构完成初始化并准备就绪时触发此事件
+ /// 架构生命周期准备就绪事件
+ /// 当架构完成初始化并准备就绪时触发此事件
///
public readonly struct ArchitectureLifecycleReadyEvent;
-
+
///
- /// 架构销毁中事件
- /// 当架构开始销毁过程时触发此事件,表示系统正在关闭
+ /// 架构销毁中事件
+ /// 当架构开始销毁过程时触发此事件,表示系统正在关闭
///
public readonly struct ArchitectureDestroyingEvent;
-
+
///
- /// 架构已销毁事件
- /// 当架构完全销毁完成后触发此事件,表示系统已关闭
+ /// 架构已销毁事件
+ /// 当架构完全销毁完成后触发此事件,表示系统已关闭
///
public readonly struct ArchitectureDestroyedEvent;
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/events/ITypeEventSystem.cs b/GFramework.Core/events/ITypeEventSystem.cs
index 491cc40..e645daf 100644
--- a/GFramework.Core/events/ITypeEventSystem.cs
+++ b/GFramework.Core/events/ITypeEventSystem.cs
@@ -1,25 +1,25 @@
namespace GFramework.Core.events;
///
-/// 类型事件系统接口,定义基于类型的事件发送、注册和注销功能
+/// 类型事件系统接口,定义基于类型的事件发送、注册和注销功能
///
public interface ITypeEventSystem
{
///
- /// 发送事件,自动创建事件实例
+ /// 发送事件,自动创建事件实例
///
/// 事件类型,必须具有无参构造函数
void Send() where T : new();
///
- /// 发送指定的事件实例
+ /// 发送指定的事件实例
///
/// 事件类型
/// 事件实例
void Send(T e);
///
- /// 注册事件监听器
+ /// 注册事件监听器
///
/// 事件类型
/// 事件处理回调函数
@@ -27,9 +27,9 @@ public interface ITypeEventSystem
IUnRegister Register(Action onEvent);
///
- /// 注销事件监听器
+ /// 注销事件监听器
///
/// 事件类型
/// 要注销的事件处理回调函数
void UnRegister(Action onEvent);
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/events/TypeEventSystem.cs b/GFramework.Core/events/TypeEventSystem.cs
index adadd71..fd54abb 100644
--- a/GFramework.Core/events/TypeEventSystem.cs
+++ b/GFramework.Core/events/TypeEventSystem.cs
@@ -1,20 +1,23 @@
namespace GFramework.Core.events;
///
-/// 类型事件系统,提供基于类型的事件发送、注册和注销功能
+/// 类型事件系统,提供基于类型的事件发送、注册和注销功能
///
public class TypeEventSystem : ITypeEventSystem
{
private readonly EasyEvents _mEvents = new();
///
- /// 发送事件,自动创建事件实例
+ /// 发送事件,自动创建事件实例
///
/// 事件类型,必须具有无参构造函数
- public void Send() where T : new() => _mEvents.GetEvent>().Trigger(new T());
+ public void Send() where T : new()
+ {
+ _mEvents.GetEvent>().Trigger(new T());
+ }
///
- /// 发送指定的事件实例
+ /// 发送指定的事件实例
///
/// 事件类型
/// 事件实例
@@ -24,17 +27,23 @@ public class TypeEventSystem : ITypeEventSystem
}
///
- /// 注册事件监听器
+ /// 注册事件监听器
///
/// 事件类型
/// 事件处理回调函数
/// 反注册接口,用于注销事件监听
- public IUnRegister Register(Action onEvent) => _mEvents.GetOrAddEvent>().Register(onEvent);
+ public IUnRegister Register(Action onEvent)
+ {
+ return _mEvents.GetOrAddEvent>().Register(onEvent);
+ }
///
- /// 注销事件监听器
+ /// 注销事件监听器
///
/// 事件类型
/// 要注销的事件处理回调函数
- public void UnRegister(Action onEvent) => _mEvents.GetEvent>().UnRegister(onEvent);
+ public void UnRegister(Action onEvent)
+ {
+ _mEvents.GetEvent>().UnRegister(onEvent);
+ }
}
\ No newline at end of file
diff --git a/GFramework.Core/ioc/IIocContainer.cs b/GFramework.Core/ioc/IIocContainer.cs
index ddc9207..dda1924 100644
--- a/GFramework.Core/ioc/IIocContainer.cs
+++ b/GFramework.Core/ioc/IIocContainer.cs
@@ -4,15 +4,15 @@ using GFramework.Core.system;
namespace GFramework.Core.ioc;
///
-/// 依赖注入容器接口,定义了服务注册、解析和管理的基本操作
+/// 依赖注入容器接口,定义了服务注册、解析和管理的基本操作
///
public interface IIocContainer : IContextAware
{
#region Register Methods
///
- /// 注册单例
- /// 一个类型只允许一个实例
+ /// 注册单例
+ /// 一个类型只允许一个实例
///
/// 要注册为单例的类型
/// 要注册的单例实例
@@ -21,27 +21,27 @@ public interface IIocContainer : IContextAware
///
- /// 注册一个实例及其所有可赋值的接口类型到容器中
+ /// 注册一个实例及其所有可赋值的接口类型到容器中
///
/// 实例的类型
/// 要注册的实例对象,不能为null
void RegisterPlurality(T instance);
///
- /// 注册系统实例,将其绑定到其所有实现的接口上
+ /// 注册系统实例,将其绑定到其所有实现的接口上
///
/// 系统实例对象
void RegisterSystem(ISystem system);
///
- /// 注册指定类型的实例到容器中
+ /// 注册指定类型的实例到容器中
///
/// 要注册的实例类型
/// 要注册的实例对象,不能为null
void Register(T instance);
///
- /// 注册指定类型的实例到容器中
+ /// 注册指定类型的实例到容器中
///
/// 要注册的实例类型
/// 要注册的实例对象
@@ -52,15 +52,15 @@ public interface IIocContainer : IContextAware
#region Get Methods
///
- /// 获取单个实例(通常用于具体类型)
- /// 如果存在多个,只返回第一个
+ /// 获取单个实例(通常用于具体类型)
+ /// 如果存在多个,只返回第一个
///
/// 期望获取的实例类型
/// 找到的第一个实例;如果未找到则返回 null
T? Get() where T : class;
///
- /// 获取指定类型的必需实例
+ /// 获取指定类型的必需实例
///
/// 期望获取的实例类型
/// 找到的唯一实例
@@ -68,14 +68,14 @@ public interface IIocContainer : IContextAware
T GetRequired() where T : class;
///
- /// 获取指定类型的所有实例(接口 / 抽象类推荐使用)
+ /// 获取指定类型的所有实例(接口 / 抽象类推荐使用)
///
/// 期望获取的实例类型
/// 所有符合条件的实例列表;如果没有则返回空数组
IReadOnlyList GetAll() where T : class;
///
- /// 获取并排序(系统调度专用)
+ /// 获取并排序(系统调度专用)
///
/// 期望获取的实例类型
/// 比较器委托,定义排序规则
@@ -87,26 +87,26 @@ public interface IIocContainer : IContextAware
#region Utility Methods
///
- /// 检查容器中是否包含指定类型的实例
+ /// 检查容器中是否包含指定类型的实例
///
/// 要检查的类型
/// 如果容器中包含指定类型的实例则返回true,否则返回false
bool Contains();
///
- /// 判断容器中是否包含某个具体的实例对象
+ /// 判断容器中是否包含某个具体的实例对象
///
/// 待查询的实例对象
/// 若容器中包含该实例则返回true,否则返回false
bool ContainsInstance(object instance);
///
- /// 清空容器中的所有实例
+ /// 清空容器中的所有实例
///
void Clear();
///
- /// 冻结容器,防止后续修改
+ /// 冻结容器,防止后续修改
///
void Freeze();
diff --git a/GFramework.Core/ioc/IocContainer.cs b/GFramework.Core/ioc/IocContainer.cs
index 4091954..cbb289a 100644
--- a/GFramework.Core/ioc/IocContainer.cs
+++ b/GFramework.Core/ioc/IocContainer.cs
@@ -12,9 +12,9 @@ public class IocContainer : ContextAwareBase, IIocContainer
#region Lock
///
- /// 读写锁对象,用于控制多线程环境下对共享资源的访问
- /// 使用ReaderWriterLockSlim提供高效的读写锁定机制
- /// 配置为不支持递归锁,避免死锁风险
+ /// 读写锁对象,用于控制多线程环境下对共享资源的访问
+ /// 使用ReaderWriterLockSlim提供高效的读写锁定机制
+ /// 配置为不支持递归锁,避免死锁风险
///
private readonly ReaderWriterLockSlim _lock = new(LockRecursionPolicy.NoRecursion);
@@ -23,8 +23,8 @@ public class IocContainer : ContextAwareBase, IIocContainer
#region Flag
///
- /// 冻结标志位,用于标识对象是否已被冻结
- /// true表示对象已冻结,不可修改;false表示对象可正常修改
+ /// 冻结标志位,用于标识对象是否已被冻结
+ /// true表示对象已冻结,不可修改;false表示对象可正常修改
///
private volatile bool _frozen;
@@ -33,14 +33,14 @@ public class IocContainer : ContextAwareBase, IIocContainer
#region Core
///
- /// 存储所有已注册对象实例的集合,用于跟踪和管理容器中的所有对象
- /// 使用HashSet确保对象唯一性,避免重复注册同一实例
+ /// 存储所有已注册对象实例的集合,用于跟踪和管理容器中的所有对象
+ /// 使用HashSet确保对象唯一性,避免重复注册同一实例
///
private readonly HashSet
protected IArchitecture Architecture;
+ ///
+ /// 初始化模型,调用抽象方法OnInit执行具体初始化逻辑
+ ///
+ void IModel.Init()
+ {
+ OnInit();
+ }
+
///
/// 获取模型所属的架构实例
///
@@ -30,14 +38,6 @@ public abstract class AbstractModel : IModel
Architecture = architecture;
}
- ///
- /// 初始化模型,调用抽象方法OnInit执行具体初始化逻辑
- ///
- void IModel.Init()
- {
- OnInit();
- }
-
///
/// 抽象初始化方法,由子类实现具体的初始化逻辑
///
diff --git a/GFramework.Core/model/IModel.cs b/GFramework.Core/model/IModel.cs
index 045d23c..a83fd2a 100644
--- a/GFramework.Core/model/IModel.cs
+++ b/GFramework.Core/model/IModel.cs
@@ -1,8 +1,4 @@
-using GFramework.Core.events;
-using GFramework.Core.rule;
-using GFramework.Core.utility;
-
-namespace GFramework.Core.model;
+namespace GFramework.Core.model;
///
/// 模型接口,定义了模型的基本行为和功能
diff --git a/GFramework.Core/query/AbstractQuery.cs b/GFramework.Core/query/AbstractQuery.cs
index 65bc706..efb6381 100644
--- a/GFramework.Core/query/AbstractQuery.cs
+++ b/GFramework.Core/query/AbstractQuery.cs
@@ -6,7 +6,7 @@ namespace GFramework.Core.query;
/// 抽象查询类,提供查询操作的基础实现
///
/// 查询结果的类型
-public abstract class AbstractQuery :ContextAwareBase, IQuery
+public abstract class AbstractQuery : ContextAwareBase, IQuery
{
///
/// 执行查询操作
@@ -16,7 +16,7 @@ public abstract class AbstractQuery :ContextAwareBase, IQuery
{
return OnDo();
}
-
+
///
/// 抽象方法,由子类实现具体的查询逻辑
///
diff --git a/GFramework.Core/query/IQuery.cs b/GFramework.Core/query/IQuery.cs
index 5d8417a..6439077 100644
--- a/GFramework.Core/query/IQuery.cs
+++ b/GFramework.Core/query/IQuery.cs
@@ -6,7 +6,7 @@ namespace GFramework.Core.query;
/// 查询接口,定义了执行查询操作的契约
///
/// 查询结果的类型
-public interface IQuery:IContextAware
+public interface IQuery : IContextAware
{
///
/// 执行查询操作并返回结果
diff --git a/GFramework.Core/rule/ContextAwareBase.cs b/GFramework.Core/rule/ContextAwareBase.cs
index cd76290..696ddbf 100644
--- a/GFramework.Core/rule/ContextAwareBase.cs
+++ b/GFramework.Core/rule/ContextAwareBase.cs
@@ -3,17 +3,17 @@
namespace GFramework.Core.rule;
///
-/// 上下文感知基类,实现了IContextAware接口,为需要感知架构上下文的类提供基础实现
+/// 上下文感知基类,实现了IContextAware接口,为需要感知架构上下文的类提供基础实现
///
public abstract class ContextAwareBase : IContextAware
{
///
- /// 获取当前实例的架构上下文
+ /// 获取当前实例的架构上下文
///
protected IArchitectureContext Context { get; private set; } = null!;
///
- /// 设置架构上下文的实现方法,由框架调用
+ /// 设置架构上下文的实现方法,由框架调用
///
/// 要设置的架构上下文实例
void IContextAware.SetContext(IArchitectureContext context)
@@ -23,7 +23,9 @@ public abstract class ContextAwareBase : IContextAware
}
///
- /// 当上下文准备就绪时调用的虚方法,子类可以重写此方法来执行上下文相关的初始化逻辑
+ /// 当上下文准备就绪时调用的虚方法,子类可以重写此方法来执行上下文相关的初始化逻辑
///
- protected virtual void OnContextReady() { }
-}
+ protected virtual void OnContextReady()
+ {
+ }
+}
\ No newline at end of file
diff --git a/GFramework.Core/rule/IContextAware.cs b/GFramework.Core/rule/IContextAware.cs
index c6319e6..d11140a 100644
--- a/GFramework.Core/rule/IContextAware.cs
+++ b/GFramework.Core/rule/IContextAware.cs
@@ -3,13 +3,13 @@
namespace GFramework.Core.rule;
///
-/// 上下文感知接口,用于为实现该接口的类提供设置架构上下文的能力
+/// 上下文感知接口,用于为实现该接口的类提供设置架构上下文的能力
///
public interface IContextAware
{
///
- /// 设置架构上下文
+ /// 设置架构上下文
///
/// 架构上下文对象,用于提供架构级别的服务和功能访问
void SetContext(IArchitectureContext context);
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/rule/ILogAware.cs b/GFramework.Core/rule/ILogAware.cs
index dec2952..d52b6e6 100644
--- a/GFramework.Core/rule/ILogAware.cs
+++ b/GFramework.Core/rule/ILogAware.cs
@@ -3,13 +3,13 @@
namespace GFramework.Core.rule;
///
-/// 定义一个支持日志记录的接口,允许实现类设置和使用日志记录器
+/// 定义一个支持日志记录的接口,允许实现类设置和使用日志记录器
///
public interface ILogAware
{
///
- /// 设置日志记录器
+ /// 设置日志记录器
///
/// 要设置的ILogger实例
void SetLogger(ILogger logger);
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core/system/ISystem.cs b/GFramework.Core/system/ISystem.cs
index 739fd5e..c9261b0 100644
--- a/GFramework.Core/system/ISystem.cs
+++ b/GFramework.Core/system/ISystem.cs
@@ -13,7 +13,7 @@ public interface ISystem : IContextAware
/// 在系统被创建后调用,用于执行系统的初始化逻辑
///
void Init();
-
+
///
/// 销毁系统
/// 在系统被销毁前调用,用于执行系统的资源清理逻辑
diff --git a/GFramework.Core/utility/AbstractContextUtility.cs b/GFramework.Core/utility/AbstractContextUtility.cs
index 5033fa5..86fa4a3 100644
--- a/GFramework.Core/utility/AbstractContextUtility.cs
+++ b/GFramework.Core/utility/AbstractContextUtility.cs
@@ -4,15 +4,15 @@ using GFramework.Core.rule;
namespace GFramework.Core.utility;
///
-/// 抽象上下文工具类,提供上下文相关的通用功能实现
-/// 继承自ContextAwareBase并实现IContextUtility接口
+/// 抽象上下文工具类,提供上下文相关的通用功能实现
+/// 继承自ContextAwareBase并实现IContextUtility接口
///
public abstract class AbstractContextUtility : ContextAwareBase, IContextUtility
{
protected ILogger Logger = null !;
///
- /// 初始化上下文工具类
+ /// 初始化上下文工具类
///
void IContextUtility.Init()
{
diff --git a/GFramework.Core/utility/IContextUtility.cs b/GFramework.Core/utility/IContextUtility.cs
index 7f597c9..34fdedb 100644
--- a/GFramework.Core/utility/IContextUtility.cs
+++ b/GFramework.Core/utility/IContextUtility.cs
@@ -3,14 +3,13 @@
namespace GFramework.Core.utility;
///
-/// 上下文工具接口,继承自IUtility和IContextAware接口
-/// 提供具有上下文感知能力的工具功能
+/// 上下文工具接口,继承自IUtility和IContextAware接口
+/// 提供具有上下文感知能力的工具功能
///
-public interface IContextUtility:IUtility,IContextAware
+public interface IContextUtility : IUtility, IContextAware
{
///
- /// 初始化上下文工具
+ /// 初始化上下文工具
///
void Init();
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Game/GFramework.Game.csproj b/GFramework.Game/GFramework.Game.csproj
index 271f741..629ae18 100644
--- a/GFramework.Game/GFramework.Game.csproj
+++ b/GFramework.Game/GFramework.Game.csproj
@@ -7,6 +7,6 @@
enable
-
+
diff --git a/GFramework.Game/assets/AbstractAssetCatalogSystem.cs b/GFramework.Game/assets/AbstractAssetCatalogSystem.cs
index f88a8ed..bac333d 100644
--- a/GFramework.Game/assets/AbstractAssetCatalogSystem.cs
+++ b/GFramework.Game/assets/AbstractAssetCatalogSystem.cs
@@ -3,20 +3,20 @@ using GFramework.Core.system;
namespace GFramework.Game.assets;
///
-/// 资源目录系统抽象基类,用于管理和注册游戏中的场景和资源。
-/// 提供了统一的接口来注册和查询不同类型的资产(如游戏单元、模板、普通资源)。
-/// 子类需要实现 方法以完成具体资产的注册逻辑。
+/// 资源目录系统抽象基类,用于管理和注册游戏中的场景和资源。
+/// 提供了统一的接口来注册和查询不同类型的资产(如游戏单元、模板、普通资源)。
+/// 子类需要实现 方法以完成具体资产的注册逻辑。
///
public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalogSystem
{
- private readonly Dictionary _sceneUnits = new();
- private readonly Dictionary _scenePages = new();
private readonly Dictionary _assets = new();
+ private readonly Dictionary _scenePages = new();
+ private readonly Dictionary _sceneUnits = new();
///
- /// 系统初始化时调用,用于触发资产注册流程。
- /// 此方法会调用抽象方法 ,由子类提供实际注册逻辑。
+ /// 系统初始化时调用,用于触发资产注册流程。
+ /// 此方法会调用抽象方法 ,由子类提供实际注册逻辑。
///
protected override void OnInit()
{
@@ -24,16 +24,15 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
}
///
- /// 抽象方法,必须在子类中重写。用于定义具体的资产注册逻辑。
- /// 在此方法中应通过调用各种 Register 方法将资产信息添加到系统中。
+ /// 抽象方法,必须在子类中重写。用于定义具体的资产注册逻辑。
+ /// 在此方法中应通过调用各种 Register 方法将资产信息添加到系统中。
///
protected abstract void RegisterAssets();
#region Register(内部 or Module 使用)
-
///
- /// 注册场景单元到资产目录中
+ /// 注册场景单元到资产目录中
///
/// 场景单元的唯一标识键
/// 场景单元资源的路径
@@ -46,7 +45,7 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
}
///
- /// 通过资产目录映射注册场景单元
+ /// 通过资产目录映射注册场景单元
///
/// 包含场景单元信息的资产目录映射对象
/// 当映射ID不是SceneUnitId类型或键已存在时抛出异常
@@ -62,7 +61,7 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
}
///
- /// 注册场景页面模板
+ /// 注册场景页面模板
///
/// 场景页面的唯一标识键
/// 场景页面资源路径
@@ -72,9 +71,9 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
if (!_scenePages.TryAdd(key, new AssetCatalog.ScenePageId(path)))
throw new InvalidOperationException($"Template key duplicated: {key}");
}
-
+
///
- /// 通过资产目录映射注册场景页面
+ /// 通过资产目录映射注册场景页面
///
/// 包含场景页面信息的资产目录映射对象
/// 当映射ID不是ScenePageId类型或键已存在时抛出异常
@@ -91,7 +90,7 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
///
- /// 注册一个通用资源(Asset),使用指定的键和路径。
+ /// 注册一个通用资源(Asset),使用指定的键和路径。
///
/// 唯一标识该资源的字符串键。
/// 该资源对应的资源路径。
@@ -103,11 +102,11 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
}
///
- /// 根据映射对象注册一个通用资源(Asset)。
+ /// 根据映射对象注册一个通用资源(Asset)。
///
/// 包含键与ID映射关系的对象。
///
- /// 当映射ID不是 类型或键重复时抛出异常。
+ /// 当映射ID不是 类型或键重复时抛出异常。
///
public void RegisterAsset(AssetCatalog.AssetCatalogMapping mapping)
{
@@ -117,51 +116,71 @@ public abstract class AbstractAssetCatalogSystem : AbstractSystem, IAssetCatalog
if (!_assets.TryAdd(mapping.Key, assetId))
throw new InvalidOperationException($"Asset key duplicated: {mapping.Key}");
}
+
#endregion
#region Query(对外)
///
- /// 根据指定的键获取场景单元标识符
+ /// 根据指定的键获取场景单元标识符
///
/// 用于查找场景单元的键值
/// 返回与指定键对应的场景单元标识符
- public AssetCatalog.SceneUnitId GetSceneUnit(string key) => _sceneUnits[key];
+ public AssetCatalog.SceneUnitId GetSceneUnit(string key)
+ {
+ return _sceneUnits[key];
+ }
///
- /// 根据指定的键获取场景页面标识符
+ /// 根据指定的键获取场景页面标识符
///
/// 用于查找场景页面的键值
/// 返回与指定键对应的场景页面标识符
- public AssetCatalog.ScenePageId GetScenePage(string key) => _scenePages[key];
+ public AssetCatalog.ScenePageId GetScenePage(string key)
+ {
+ return _scenePages[key];
+ }
///
- /// 获取指定键对应的通用资源ID。
+ /// 获取指定键对应的通用资源ID。
///
/// 要查找的通用资源键。
/// 对应的通用资源ID。
/// 如果未找到指定键则抛出异常。
- public AssetCatalog.AssetId GetAsset(string key) => _assets[key];
+ public AssetCatalog.AssetId GetAsset(string key)
+ {
+ return _assets[key];
+ }
///
- /// 检查是否存在指定键的场景单元
+ /// 检查是否存在指定键的场景单元
///
/// 用于查找场景单元的键值
/// 存在返回true,否则返回false
- public bool HasSceneUnit(string key) => _sceneUnits.ContainsKey(key);
+ public bool HasSceneUnit(string key)
+ {
+ return _sceneUnits.ContainsKey(key);
+ }
///
- /// 检查是否存在指定键的场景页面
+ /// 检查是否存在指定键的场景页面
///
/// 用于查找场景页面的键值
/// 存在返回true,否则返回false
- public bool HasScenePage(string key) => _scenePages.ContainsKey(key);
+ public bool HasScenePage(string key)
+ {
+ return _scenePages.ContainsKey(key);
+ }
///
- /// 判断是否存在指定键的通用资源。
+ /// 判断是否存在指定键的通用资源。
///
/// 要检查的通用资源键。
/// 若存在返回 true,否则返回 false。
- public bool HasAsset(string key) => _assets.ContainsKey(key);
+ public bool HasAsset(string key)
+ {
+ return _assets.ContainsKey(key);
+ }
+
#endregion
-}
+}
\ No newline at end of file
diff --git a/GFramework.Game/assets/AssetCatalog.cs b/GFramework.Game/assets/AssetCatalog.cs
index 221f857..f1abd49 100644
--- a/GFramework.Game/assets/AssetCatalog.cs
+++ b/GFramework.Game/assets/AssetCatalog.cs
@@ -1,47 +1,45 @@
namespace GFramework.Game.assets;
///
-/// 资源目录类,用于定义和管理游戏中的场景和资源标识符
+/// 资源目录类,用于定义和管理游戏中的场景和资源标识符
///
public static class AssetCatalog
{
///
- /// 资源标识符接口,定义了资源路径的访问接口
+ /// 资源标识符接口,定义了资源路径的访问接口
///
public interface IAssetId
{
///
- /// 获取资源的路径
+ /// 获取资源的路径
///
string Path { get; }
}
///
- /// 资源目录映射结构体,用于存储资源目录的键值对映射关系
+ /// 资源目录映射结构体,用于存储资源目录的键值对映射关系
///
/// 资源目录的键
/// 资源标识符
public readonly record struct AssetCatalogMapping(string Key, IAssetId Id);
-
+
///
- /// 场景页面资源标识符结构体,用于标识场景页面资源
+ /// 场景页面资源标识符结构体,用于标识场景页面资源
///
/// 场景页面资源路径
public readonly record struct ScenePageId(string Path) : IAssetId;
-
+
///
- /// 场景单元资源标识符结构体,用于标识场景单元资源
+ /// 场景单元资源标识符结构体,用于标识场景单元资源
///
/// 场景单元资源路径
public readonly record struct SceneUnitId(string Path) : IAssetId;
-
+
///
- /// 通用资源标识符结构体,实现IAssetId接口
+ /// 通用资源标识符结构体,实现IAssetId接口
///
/// 资源路径
public readonly record struct AssetId(string Path) : IAssetId;
-
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Game/assets/IAssetCatalogSystem.cs b/GFramework.Game/assets/IAssetCatalogSystem.cs
index 2f2345b..660eb15 100644
--- a/GFramework.Game/assets/IAssetCatalogSystem.cs
+++ b/GFramework.Game/assets/IAssetCatalogSystem.cs
@@ -3,19 +3,19 @@
namespace GFramework.Game.assets;
///
-/// 资源目录系统接口,用于管理场景和资源的获取与查询
+/// 资源目录系统接口,用于管理场景和资源的获取与查询
///
public interface IAssetCatalogSystem : ISystem
{
///
- /// 根据指定的键获取场景单元标识符
+ /// 根据指定的键获取场景单元标识符
///
/// 用于查找场景单元的键值
/// 返回与指定键对应的场景单元标识符
AssetCatalog.SceneUnitId GetSceneUnit(string key);
///
- /// 根据指定的键获取场景页面标识符
+ /// 根据指定的键获取场景页面标识符
///
/// 用于查找场景页面的键值
/// 返回与指定键对应的场景页面标识符
@@ -23,14 +23,14 @@ public interface IAssetCatalogSystem : ISystem
///
- /// 根据指定的键获取资源ID
+ /// 根据指定的键获取资源ID
///
/// 用于查找资源的键值
/// 返回对应的资源ID,如果未找到则返回默认值
AssetCatalog.AssetId GetAsset(string key);
///
- /// 注册场景单元到资产目录中
+ /// 注册场景单元到资产目录中
///
/// 场景单元的唯一标识键
/// 场景单元资源的路径
@@ -38,14 +38,14 @@ public interface IAssetCatalogSystem : ISystem
public void RegisterSceneUnit(string key, string path);
///
- /// 通过资产目录映射注册场景单元
+ /// 通过资产目录映射注册场景单元
///
/// 包含场景单元信息的资产目录映射对象
/// 当映射ID不是SceneUnitId类型或键已存在时抛出异常
public void RegisterSceneUnit(AssetCatalog.AssetCatalogMapping mapping);
///
- /// 注册场景页面模板
+ /// 注册场景页面模板
///
/// 场景页面的唯一标识键
/// 场景页面资源路径
@@ -53,28 +53,28 @@ public interface IAssetCatalogSystem : ISystem
void RegisterScenePage(string key, string path);
///
- /// 通过资产目录映射注册场景页面
+ /// 通过资产目录映射注册场景页面
///
/// 包含场景页面信息的资产目录映射对象
/// 当映射ID不是ScenePageId类型或键已存在时抛出异常
void RegisterScenePage(AssetCatalog.AssetCatalogMapping mapping);
///
- /// 注册普通资产资源到资产目录中
+ /// 注册普通资产资源到资产目录中
///
/// 资产的唯一标识键值
/// 资产资源的路径
void RegisterAsset(string key, string path);
///
- /// 根据映射配置注册普通资产资源到资产目录中
+ /// 根据映射配置注册普通资产资源到资产目录中
///
/// 包含键值和路径映射关系的配置对象
void RegisterAsset(AssetCatalog.AssetCatalogMapping mapping);
///
- /// 检查是否存在指定键的场景单元
+ /// 检查是否存在指定键的场景单元
///
/// 用于查找场景单元的键值
/// 存在返回true,否则返回false
@@ -82,17 +82,16 @@ public interface IAssetCatalogSystem : ISystem
///
- /// 检查是否存在指定键的场景页面
+ /// 检查是否存在指定键的场景页面
///
/// 用于查找场景页面的键值
/// 存在返回true,否则返回false
bool HasScenePage(string key);
///
- /// 检查是否存在指定键的资源
+ /// 检查是否存在指定键的资源
///
/// 用于查找资源的键值
/// 存在返回true,否则返回false
bool HasAsset(string key);
-
}
\ No newline at end of file
diff --git a/GFramework.Game/assets/IResourceFactorySystem.cs b/GFramework.Game/assets/IResourceFactorySystem.cs
index a6a0753..2ecd778 100644
--- a/GFramework.Game/assets/IResourceFactorySystem.cs
+++ b/GFramework.Game/assets/IResourceFactorySystem.cs
@@ -3,24 +3,23 @@
namespace GFramework.Game.assets;
///
-/// 资源工厂系统接口,用于获取指定类型的资源创建函数
+/// 资源工厂系统接口,用于获取指定类型的资源创建函数
///
public interface IResourceFactorySystem : ISystem
{
///
- /// 根据指定键名获取指定类型T的资源创建函数
+ /// 根据指定键名获取指定类型T的资源创建函数
///
/// 要获取创建函数的资源类型
/// 用于标识资源的键名
/// 返回一个创建T类型实例的函数委托
Func GetFactory(string key);
-
+
///
- /// 根据资产目录映射获取指定类型T的资源创建函数
+ /// 根据资产目录映射获取指定类型T的资源创建函数
///
/// 要获取创建函数的资源类型
/// 资产目录映射信息
/// 返回一个创建T类型实例的函数委托
Func GetFactory(AssetCatalog.AssetCatalogMapping mapping);
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Game/assets/ResourceFactory.cs b/GFramework.Game/assets/ResourceFactory.cs
index b46e258..d85babd 100644
--- a/GFramework.Game/assets/ResourceFactory.cs
+++ b/GFramework.Game/assets/ResourceFactory.cs
@@ -1,82 +1,85 @@
namespace GFramework.Game.assets;
///
-/// 资源工厂类,用于注册和解析各种资源的创建工厂
+/// 资源工厂类,用于注册和解析各种资源的创建工厂
///
public static class ResourceFactory
{
///
- /// 可预加载条目接口,定义了是否需要预加载以及执行工厂的方法
+ /// 可预加载条目接口,定义了是否需要预加载以及执行工厂的方法
///
private interface IPreloadableEntry
{
///
- /// 获取一个值,表示该资源是否需要预加载
+ /// 获取一个值,表示该资源是否需要预加载
///
bool Preload { get; }
///
- /// 执行与该条目关联的工厂方法
- ///
- void ExecuteFactory();
-
- ///
- /// 获取资源类型
+ /// 获取资源类型
///
Type ResourceType { get; }
-
+
///
- /// 获取资源键值
+ /// 获取资源键值
///
string Key { get; }
+
+ ///
+ /// 执行与该条目关联的工厂方法
+ ///
+ void ExecuteFactory();
}
///
- /// 表示一个具体的资源工厂条目,实现 IPreloadableEntry 接口
+ /// 表示一个具体的资源工厂条目,实现 IPreloadableEntry 接口
///
/// 资源类型
private sealed class Entry(string key, Func factory, bool preload) : IPreloadableEntry
{
///
- /// 获取用于创建资源的工厂函数
+ /// 获取用于创建资源的工厂函数
///
public Func Factory { get; } = factory;
///
- /// 获取一个值,表示该资源是否需要预加载
+ /// 获取一个值,表示该资源是否需要预加载
///
public bool Preload { get; } = preload;
///
- /// 执行工厂函数以创建资源实例
+ /// 执行工厂函数以创建资源实例
///
- public void ExecuteFactory() => Factory();
+ public void ExecuteFactory()
+ {
+ Factory();
+ }
///
- /// 获取资源的类型
+ /// 获取资源的类型
///
public Type ResourceType => typeof(T);
///
- /// 获取资源的键值
+ /// 获取资源的键值
///
public string Key { get; } = key;
}
-
+
///
- /// 工厂注册表,管理所有已注册的资源工厂
+ /// 工厂注册表,管理所有已注册的资源工厂
///
public sealed class Registry
{
///
- /// 存储所有已注册的工厂函数,键为资源类型,值为对应的工厂条目对象
+ /// 存储所有已注册的工厂函数,键为资源类型,值为对应的工厂条目对象
///
private readonly Dictionary<(Type type, string key), IPreloadableEntry> _factories = new();
///
- /// 注册指定类型的资源工厂
+ /// 注册指定类型的资源工厂
///
/// 要注册的资源类型
/// 键
@@ -93,7 +96,7 @@ public static class ResourceFactory
}
///
- /// 解析并获取指定类型的工厂函数
+ /// 解析并获取指定类型的工厂函数
///
/// 要获取工厂函数的资源类型
/// 资源键
@@ -105,26 +108,21 @@ public static class ResourceFactory
if (_factories.TryGetValue(dictKey, out var entry)
&& entry is Entry typed)
- {
return typed.Factory;
- }
throw new InvalidOperationException(
$"Factory not registered: {typeof(T).Name} with key '{key}'");
}
-
+
///
- /// 预加载所有标记为需要预加载的资源
+ /// 预加载所有标记为需要预加载的资源
///
public void PreloadAll()
{
// 遍历所有已注册的工厂
foreach (var entry in _factories.Values.Where(entry => entry.Preload))
- {
// 执行其工厂方法进行预加载
entry.ExecuteFactory();
- }
}
}
-
-}
+}
\ No newline at end of file
diff --git a/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs b/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs
index 704cf0c..17afa44 100644
--- a/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs
+++ b/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs
@@ -4,20 +4,20 @@ using System;
namespace GFramework.Godot.SourceGenerators.Attributes.logging;
///
-/// Godot日志特性,用于在类上标记以自动生成日志字段
+/// Godot日志特性,用于在类上标记以自动生成日志字段
///
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class GodotLogAttribute : Attribute
{
///
- /// 初始化 GodotLogAttribute 类的新实例
+ /// 初始化 GodotLogAttribute 类的新实例
///
public GodotLogAttribute()
{
}
///
- /// 初始化 GodotLogAttribute 类的新实例
+ /// 初始化 GodotLogAttribute 类的新实例
///
/// 日志分类名
public GodotLogAttribute(string? name)
diff --git a/GFramework.Godot.SourceGenerators/logging/Diagnostic.cs b/GFramework.Godot.SourceGenerators/logging/Diagnostic.cs
deleted file mode 100644
index bf235c0..0000000
--- a/GFramework.Godot.SourceGenerators/logging/Diagnostic.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using Microsoft.CodeAnalysis;
-
-namespace GFramework.Godot.SourceGenerators.logging;
-
-///
-/// 提供诊断描述符的静态类,用于GFramework日志生成器的编译时检查
-///
-internal static class GodotLoggerDiagnostics
-{
- ///
- /// 诊断描述符:标识使用[GodotLog]特性的类必须声明为partial
- ///
- ///
- /// ID: GFLOG001
- /// 严重性: Error
- /// 分类: GFramework.Godot.Logging
- ///
- public static readonly DiagnosticDescriptor MustBePartial =
- new(
- id: "GFLOG001",
- title: "Class must be partial",
- messageFormat: "Class '{0}' must be declared as partial to use [GodotLog]",
- category: "GFramework.Godot.Logging",
- DiagnosticSeverity.Error,
- isEnabledByDefault: true
- );
-
-
- ///
- /// 诊断描述符:标识GodotLogAttribute无法在指定类上生成Logger
- ///
- ///
- /// ID: GFW_LOG001
- /// 严重性: Warning
- /// 分类: GFramework.Godot.Logging
- ///
- public static readonly DiagnosticDescriptor LogAttributeInvalid = new(
- id: "GFW_LOG001",
- title: "GodotLogAttribute cannot generate Logger",
- messageFormat: "GodotLogAttribute on class '{0}' is ineffective: {1}",
- category: "GFramework.Godot.Logging",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
-}
\ No newline at end of file
diff --git a/GFramework.Godot.SourceGenerators/logging/GodotLoggerDiagnostic.cs b/GFramework.Godot.SourceGenerators/logging/GodotLoggerDiagnostic.cs
new file mode 100644
index 0000000..66a046d
--- /dev/null
+++ b/GFramework.Godot.SourceGenerators/logging/GodotLoggerDiagnostic.cs
@@ -0,0 +1,44 @@
+using Microsoft.CodeAnalysis;
+
+namespace GFramework.Godot.SourceGenerators.logging;
+
+///
+/// 提供诊断描述符的静态类,用于GFramework日志生成器的编译时检查
+///
+internal static class GodotLoggerDiagnostics
+{
+ ///
+ /// 诊断描述符:标识使用[GodotLog]特性的类必须声明为partial
+ ///
+ ///
+ /// ID: GFLOG001
+ /// 严重性: Error
+ /// 分类: GFramework.Godot.Logging
+ ///
+ public static readonly DiagnosticDescriptor MustBePartial =
+ new(
+ "GFLOG001",
+ "Class must be partial",
+ "Class '{0}' must be declared as partial to use [GodotLog]",
+ "GFramework.Godot.Logging",
+ DiagnosticSeverity.Error,
+ true
+ );
+
+
+ ///
+ /// 诊断描述符:标识GodotLogAttribute无法在指定类上生成Logger
+ ///
+ ///
+ /// ID: GFW_LOG001
+ /// 严重性: Warning
+ /// 分类: GFramework.Godot.Logging
+ ///
+ public static readonly DiagnosticDescriptor LogAttributeInvalid = new(
+ "GFW_LOG001",
+ "GodotLogAttribute cannot generate Logger",
+ "GodotLogAttribute on class '{0}' is ineffective: {1}",
+ "GFramework.Godot.Logging",
+ DiagnosticSeverity.Warning,
+ true);
+}
\ No newline at end of file
diff --git a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs
index b4b5cab..89b04e4 100644
--- a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs
+++ b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs
@@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis.Text;
namespace GFramework.Godot.SourceGenerators.logging;
///
-/// 日志生成器,用于为标记了LogAttribute的类自动生成日志字段
+/// 日志生成器,用于为标记了LogAttribute的类自动生成日志字段
///
[Generator]
public sealed class GodotLoggerGenerator : IIncrementalGenerator
@@ -21,7 +21,7 @@ public sealed class GodotLoggerGenerator : IIncrementalGenerator
private const string AttributeShortNameWithoutSuffix = "GodotLog";
///
- /// 初始化生成器,设置语法过滤和代码生成逻辑
+ /// 初始化生成器,设置语法过滤和代码生成逻辑
///
/// 增量生成器初始化上下文
public void Initialize(IncrementalGeneratorInitializationContext context)
@@ -86,7 +86,7 @@ public sealed class GodotLoggerGenerator : IIncrementalGenerator
}
///
- /// 获取类符号上的LogAttribute特性
+ /// 获取类符号上的LogAttribute特性
///
/// 类符号
/// LogAttribute特性数据,如果不存在则返回null
@@ -104,7 +104,7 @@ public sealed class GodotLoggerGenerator : IIncrementalGenerator
}
///
- /// 生成日志字段代码
+ /// 生成日志字段代码
///
/// 类符号
/// LogAttribute特性数据
@@ -173,7 +173,7 @@ public sealed class GodotLoggerGenerator : IIncrementalGenerator
}
///
- /// 从特性数据中获取命名参数的值
+ /// 从特性数据中获取命名参数的值
///
/// 特性数据
/// 参数名称
diff --git a/GFramework.Godot/GFramework.Godot.csproj b/GFramework.Godot/GFramework.Godot.csproj
index fc85a79..6c052b3 100644
--- a/GFramework.Godot/GFramework.Godot.csproj
+++ b/GFramework.Godot/GFramework.Godot.csproj
@@ -14,7 +14,7 @@
-
+
diff --git a/GFramework.Godot/architecture/AbstractArchitecture.cs b/GFramework.Godot/architecture/AbstractArchitecture.cs
index c2d2135..49943ab 100644
--- a/GFramework.Godot/architecture/AbstractArchitecture.cs
+++ b/GFramework.Godot/architecture/AbstractArchitecture.cs
@@ -6,46 +6,45 @@ using Godot;
namespace GFramework.Godot.architecture;
///
-/// 抽象架构类,为特定类型的架构提供基础实现框架。
-/// 此类负责管理架构的初始化、生命周期绑定以及扩展模块的安装与销毁。
+/// 抽象架构类,为特定类型的架构提供基础实现框架。
+/// 此类负责管理架构的初始化、生命周期绑定以及扩展模块的安装与销毁。
///
-public abstract class AbstractArchitecture: Architecture
+public abstract class AbstractArchitecture : Architecture
{
-
///
- /// 架构锚点节点的唯一标识名称
- /// 用于在Godot场景树中创建和查找架构锚点节点
+ /// 架构锚点节点的唯一标识名称
+ /// 用于在Godot场景树中创建和查找架构锚点节点
///
private const string ArchitectureAnchorName = $"__{GFrameworkConstants.FrameworkName}__ArchitectureAnchor__";
-
+
///
- /// 存储所有已安装的Godot架构扩展组件列表
- /// 用于在架构销毁时正确清理所有扩展资源
+ /// 存储所有已安装的Godot架构扩展组件列表
+ /// 用于在架构销毁时正确清理所有扩展资源
///
private readonly List _extensions = [];
-
+
///
- /// 架构锚点节点引用
- /// 用于将架构绑定到Godot生命周期并作为扩展节点的父节点
+ /// 架构锚点节点引用
+ /// 用于将架构绑定到Godot生命周期并作为扩展节点的父节点
///
private ArchitectureAnchor? _anchor;
///
- /// 获取架构根节点。如果尚未初始化或已被销毁,则抛出异常。
+ /// 标记架构是否已被销毁的状态标志
+ /// 用于防止架构被重复销毁,确保资源清理只执行一次
+ ///
+ private bool _destroyed;
+
+ ///
+ /// 获取架构根节点。如果尚未初始化或已被销毁,则抛出异常。
///
/// 当架构未准备就绪时抛出。
protected Node ArchitectureRoot => _anchor ?? throw new InvalidOperationException("Architecture root not ready");
- ///
- /// 标记架构是否已被销毁的状态标志
- /// 用于防止架构被重复销毁,确保资源清理只执行一次
- ///
- private bool _destroyed;
-
///
- /// 初始化架构,按顺序注册模型、系统和工具。
- /// 包括将架构绑定到Godot生命周期并调用模块安装逻辑。
+ /// 初始化架构,按顺序注册模型、系统和工具。
+ /// 包括将架构绑定到Godot生命周期并调用模块安装逻辑。
///
protected override void Init()
{
@@ -54,14 +53,14 @@ public abstract class AbstractArchitecture: Architecture
}
///
- /// 安装模块抽象方法,由子类实现具体的模块注册逻辑。
- /// 子类应在此方法中完成所有模型、系统及工具的注册工作。
+ /// 安装模块抽象方法,由子类实现具体的模块注册逻辑。
+ /// 子类应在此方法中完成所有模型、系统及工具的注册工作。
///
protected abstract void InstallModules();
///
- /// 将架构绑定到Godot生命周期中,确保在场景树销毁时能够正确清理资源。
- /// 通过创建一个锚节点来监听场景树的销毁事件。
+ /// 将架构绑定到Godot生命周期中,确保在场景树销毁时能够正确清理资源。
+ /// 通过创建一个锚节点来监听场景树的销毁事件。
///
private void AttachToGodotLifecycle()
{
@@ -82,9 +81,9 @@ public abstract class AbstractArchitecture: Architecture
tree.Root.CallDeferred(Node.MethodName.AddChild, _anchor);
}
-
+
///
- /// 安装Godot模块扩展
+ /// 安装Godot模块扩展
///
/// 模块类型,必须实现IGodotModule接口
/// 要安装的模块实例
@@ -92,30 +91,29 @@ public abstract class AbstractArchitecture: Architecture
protected async Task InstallGodotModule(TModule module) where TModule : IGodotModule
{
module.Install(this);
-
+
// 检查锚点是否已初始化,未初始化则抛出异常
if (_anchor == null)
throw new InvalidOperationException("Anchor not initialized");
-
+
// 等待锚点准备就绪
await _anchor.WaitUntilReady();
-
+
// 延迟调用将扩展节点添加为锚点的子节点
_anchor.CallDeferred(Node.MethodName.AddChild, module.Node);
// 调用扩展的附加回调方法
module.OnAttach(this);
-
+
// 将扩展添加到扩展集合中
_extensions.Add(module);
}
-
///
- /// 销毁架构及其相关资源。
- /// 调用所有已安装扩展的OnDetach方法,并清空扩展列表。
- /// 若已被销毁则直接返回。
+ /// 销毁架构及其相关资源。
+ /// 调用所有已安装扩展的OnDetach方法,并清空扩展列表。
+ /// 若已被销毁则直接返回。
///
public override void Destroy()
{
diff --git a/GFramework.Godot/architecture/AbstractGodotModule.cs b/GFramework.Godot/architecture/AbstractGodotModule.cs
index 2d2c09f..e0bf752 100644
--- a/GFramework.Godot/architecture/AbstractGodotModule.cs
+++ b/GFramework.Godot/architecture/AbstractGodotModule.cs
@@ -4,54 +4,50 @@ using Godot;
namespace GFramework.Godot.architecture;
///
-/// 抽象的Godot模块基类,用于定义Godot框架中的模块行为
+/// 抽象的Godot模块基类,用于定义Godot框架中的模块行为
///
-public abstract class AbstractGodotModule: IGodotModule
+public abstract class AbstractGodotModule : IGodotModule
{
///
- /// 当架构阶段发生变化时调用此方法
+ /// 当架构阶段发生变化时调用此方法
///
/// 当前的架构阶段
/// 架构实例
public virtual void OnPhase(ArchitecturePhase phase, IArchitecture arch)
{
-
}
///
- /// 当架构阶段发生变化时调用此方法
+ /// 当架构阶段发生变化时调用此方法
///
/// 当前的架构阶段
public virtual void OnArchitecturePhase(ArchitecturePhase phase)
{
-
}
///
- /// 安装模块到指定架构中
+ /// 安装模块到指定架构中
///
/// 要安装到的架构实例
public abstract void Install(IArchitecture architecture);
///
- /// 获取模块关联的Godot节点
+ /// 获取模块关联的Godot节点
///
public abstract Node Node { get; }
-
+
///
- /// 当模块被附加到架构时调用此方法
+ /// 当模块被附加到架构时调用此方法
///
/// 被附加到的架构实例
public virtual void OnAttach(Architecture architecture)
{
-
}
///
- /// 当模块从架构中分离时调用此方法
+ /// 当模块从架构中分离时调用此方法
///
public virtual void OnDetach()
{
-
}
-}
+}
\ No newline at end of file
diff --git a/GFramework.Godot/architecture/ArchitectureAnchor.cs b/GFramework.Godot/architecture/ArchitectureAnchor.cs
index 4f41564..2884184 100644
--- a/GFramework.Godot/architecture/ArchitectureAnchor.cs
+++ b/GFramework.Godot/architecture/ArchitectureAnchor.cs
@@ -3,29 +3,28 @@
namespace GFramework.Godot.architecture;
///
-/// 架构锚点节点类,用于在Godot场景树中作为架构组件的根节点
-/// 该类提供了退出时的回调绑定功能,可以在节点从场景树中移除时执行清理操作
+/// 架构锚点节点类,用于在Godot场景树中作为架构组件的根节点
+/// 该类提供了退出时的回调绑定功能,可以在节点从场景树中移除时执行清理操作
///
public partial class ArchitectureAnchor : Node
{
private Action? _onExit;
+
///
- /// 绑定节点退出时的回调动作
+ /// 绑定节点退出时的回调动作
///
/// 当节点从场景树退出时要执行的动作
public void Bind(Action onExit)
{
if (_onExit != null)
- {
GD.PushWarning(
$"{nameof(ArchitectureAnchor)} already bound. Rebinding will override previous callback.");
- }
_onExit = onExit;
}
-
+
///
- /// 当节点从场景树中移除时调用此方法
- /// 执行绑定的退出回调并清理引用
+ /// 当节点从场景树中移除时调用此方法
+ /// 执行绑定的退出回调并清理引用
///
public override void _ExitTree()
{
@@ -33,5 +32,4 @@ public partial class ArchitectureAnchor : Node
_onExit = null;
callback?.Invoke();
}
-}
-
+}
\ No newline at end of file
diff --git a/GFramework.Godot/architecture/IGodotModule.cs b/GFramework.Godot/architecture/IGodotModule.cs
index 154f521..1b18fa4 100644
--- a/GFramework.Godot/architecture/IGodotModule.cs
+++ b/GFramework.Godot/architecture/IGodotModule.cs
@@ -4,23 +4,23 @@ using Godot;
namespace GFramework.Godot.architecture;
///
-/// Godot模块接口,定义了Godot引擎中模块的基本行为和属性
+/// Godot模块接口,定义了Godot引擎中模块的基本行为和属性
///
public interface IGodotModule : IArchitectureModule
{
///
- /// 获取模块关联的Godot节点
+ /// 获取模块关联的Godot节点
///
Node Node { get; }
///
- /// 当模块被附加到架构时调用
+ /// 当模块被附加到架构时调用
///
/// 要附加到的架构实例
void OnAttach(Architecture architecture);
///
- /// 当模块从架构分离时调用
+ /// 当模块从架构分离时调用
///
void OnDetach();
}
\ No newline at end of file
diff --git a/GFramework.Godot/assets/AbstractResourceFactorySystem.cs b/GFramework.Godot/assets/AbstractResourceFactorySystem.cs
index 5745f45..982b645 100644
--- a/GFramework.Godot/assets/AbstractResourceFactorySystem.cs
+++ b/GFramework.Godot/assets/AbstractResourceFactorySystem.cs
@@ -7,29 +7,17 @@ using Godot;
namespace GFramework.Godot.assets;
///
-/// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。
-/// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。
+/// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。
+/// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。
///
public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitectureLifecycle
{
+ private IAssetCatalogSystem? _assetCatalogSystem;
private ResourceFactory.Registry? _registry;
private IResourceLoadSystem? _resourceLoadSystem;
- private IAssetCatalogSystem? _assetCatalogSystem;
///
- /// 系统初始化方法,在系统启动时执行一次。
- /// 初始化资源注册表,并获取依赖的资源加载系统和资产目录系统。
- /// 最后执行所有已注册资源的预加载操作。
- ///
- protected override void OnInit()
- {
- _registry = new ResourceFactory.Registry();
- _resourceLoadSystem = Context.GetSystem();
- _assetCatalogSystem = Context.GetSystem();
- }
-
- ///
- /// 架构阶段回调,在架构就绪时注册和预加载资源
+ /// 架构阶段回调,在架构就绪时注册和预加载资源
///
/// 当前架构阶段
/// 架构实例
@@ -44,34 +32,51 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
}
}
- ///
- /// 注册系统所需的各种资源类型。由子类实现具体注册逻辑。
- ///
- protected abstract void RegisterResources();
-
///
- /// 根据指定的键获取资源工厂函数。
+ /// 根据指定的键获取资源工厂函数。
///
/// 资源类型
/// 资源键
/// 返回创建指定类型资源的工厂函数
- public Func GetFactory(string key) => _registry!.ResolveFactory(key);
+ public Func GetFactory(string key)
+ {
+ return _registry!.ResolveFactory(key);
+ }
///
- /// 根据资产目录映射信息获取资源工厂函数。
+ /// 根据资产目录映射信息获取资源工厂函数。
///
/// 资源类型
/// 资产目录映射信息
/// 返回创建指定类型资源的工厂函数
- public Func GetFactory(AssetCatalog.AssetCatalogMapping mapping) => _registry!.ResolveFactory(mapping.Key);
+ public Func GetFactory(AssetCatalog.AssetCatalogMapping mapping)
+ {
+ return _registry!.ResolveFactory(mapping.Key);
+ }
+
+ ///
+ /// 系统初始化方法,在系统启动时执行一次。
+ /// 初始化资源注册表,并获取依赖的资源加载系统和资产目录系统。
+ /// 最后执行所有已注册资源的预加载操作。
+ ///
+ protected override void OnInit()
+ {
+ _registry = new ResourceFactory.Registry();
+ _resourceLoadSystem = Context.GetSystem();
+ _assetCatalogSystem = Context.GetSystem();
+ }
+
+ ///
+ /// 注册系统所需的各种资源类型。由子类实现具体注册逻辑。
+ ///
+ protected abstract void RegisterResources();
#region Register Helpers(声明式)
-
///
- /// 注册场景单元到资源管理系统中
+ /// 注册场景单元到资源管理系统中
///
/// 场景单元类型,必须继承自Node
/// 场景单元键值,用于标识特定的场景单元资源
@@ -92,7 +97,7 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
///
- /// 注册场景页面到资源管理系统中
+ /// 注册场景页面到资源管理系统中
///
/// 场景页面类型,必须继承自Node
/// 场景页面键值,用于标识特定的场景页面资源
@@ -112,7 +117,7 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
}
///
- /// 注册通用资产资源到资源管理系统中
+ /// 注册通用资产资源到资源管理系统中
///
/// 资产类型,必须继承自Resource
/// 资产键值,用于标识特定的资产资源
@@ -131,6 +136,5 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
);
}
-
#endregion
}
\ No newline at end of file
diff --git a/GFramework.Godot/assets/IResourceLoadSystem.cs b/GFramework.Godot/assets/IResourceLoadSystem.cs
index 81b1a96..81b3481 100644
--- a/GFramework.Godot/assets/IResourceLoadSystem.cs
+++ b/GFramework.Godot/assets/IResourceLoadSystem.cs
@@ -5,35 +5,35 @@ using Godot;
namespace GFramework.Godot.system;
///
-/// 资源加载系统接口,提供资源和场景的加载、实例化、预加载等功能
+/// 资源加载系统接口,提供资源和场景的加载、实例化、预加载等功能
///
public interface IResourceLoadSystem : ISystem
{
///
- /// 加载指定路径的资源
+ /// 加载指定路径的资源
///
/// 资源类型,必须继承自Resource
/// 资源路径
/// 加载的资源实例
public T? LoadResource(string path) where T : Resource;
-
+
///
- /// 获取场景加载器,用于延迟加载场景
+ /// 获取场景加载器,用于延迟加载场景
///
/// 场景路径
/// 场景的延迟加载包装器
public Lazy GetSceneLoader(string path);
///
- /// 创建指定路径场景的实例
+ /// 创建指定路径场景的实例
///
/// 节点类型,必须继承自Node
/// 场景路径
/// 场景实例化的节点对象
public T? CreateInstance(string path) where T : Node;
-
+
///
- /// 获取或注册游戏单位工厂函数
+ /// 获取或注册游戏单位工厂函数
///
/// 节点类型,必须继承自Node
/// 场景资源标识符
@@ -43,7 +43,7 @@ public interface IResourceLoadSystem : ISystem
) where T : Node;
///
- /// 获取或注册模板资源工厂函数
+ /// 获取或注册模板资源工厂函数
///
/// 节点类型,必须继承自Node
/// 模板资源标识符
@@ -53,7 +53,7 @@ public interface IResourceLoadSystem : ISystem
) where T : Node;
///
- /// 获取或注册通用资产工厂函数
+ /// 获取或注册通用资产工厂函数
///
/// 资源类型,必须继承自Resource
/// 资产资源标识符
@@ -65,19 +65,19 @@ public interface IResourceLoadSystem : ISystem
) where T : Resource;
///
- /// 预加载指定路径的多个资源
+ /// 预加载指定路径的多个资源
///
/// 需要预加载的资源路径集合
public void Preload(IEnumerable paths);
-
+
///
- /// 卸载指定路径的资源
+ /// 卸载指定路径的资源
///
/// 需要卸载的资源路径
public void Unload(string path);
-
+
///
- /// 清除所有已加载的资源
+ /// 清除所有已加载的资源
///
public void ClearAll();
-}
+}
\ No newline at end of file
diff --git a/GFramework.Godot/assets/ResourceLoadSystem.cs b/GFramework.Godot/assets/ResourceLoadSystem.cs
index 204ef44..1bf0917 100644
--- a/GFramework.Godot/assets/ResourceLoadSystem.cs
+++ b/GFramework.Godot/assets/ResourceLoadSystem.cs
@@ -5,90 +5,33 @@ using Godot;
namespace GFramework.Godot.system;
///
-/// 资源加载系统,用于统一管理和缓存Godot资源(如场景、纹理等)的加载与实例化。
-/// 提供基础加载、场景实例化、资源工厂注册以及缓存管理功能。
+/// 资源加载系统,用于统一管理和缓存Godot资源(如场景、纹理等)的加载与实例化。
+/// 提供基础加载、场景实例化、资源工厂注册以及缓存管理功能。
///
public class ResourceLoadSystem : AbstractSystem, IResourceLoadSystem
{
///
- /// 已加载的资源缓存字典,键为资源路径,值为已加载的Resource对象。
+ /// 已加载的资源缓存字典,键为资源路径,值为已加载的Resource对象。
///
private readonly Dictionary _loadedResources = new();
///
- /// 场景懒加载器缓存,键为场景路径,值为延迟加载的PackedScene对象。
- ///
- private readonly Dictionary> _sceneLoaders = new();
-
- ///
- /// 场景实例化工厂委托缓存,键为场景路径,值为创建该场景实例的Func委托。
- ///
- private readonly Dictionary _sceneFactories = new();
-
- ///
- /// 资源获取/复制工厂委托缓存,键为资源路径,值为获取或复制资源的Func委托。
+ /// 资源获取/复制工厂委托缓存,键为资源路径,值为获取或复制资源的Func委托。
///
private readonly Dictionary _resourceFactories = new();
///
- /// 初始化方法,在系统初始化时打印日志信息。
+ /// 场景实例化工厂委托缓存,键为场景路径,值为创建该场景实例的Func委托。
///
- protected override void OnInit()
- {
- }
-
- #region 基础加载
+ private readonly Dictionary _sceneFactories = new();
///
- /// 加载指定类型的资源并进行缓存。如果资源已经加载过则直接从缓存中返回。
+ /// 场景懒加载器缓存,键为场景路径,值为延迟加载的PackedScene对象。
///
- /// 要加载的资源类型,必须继承自Resource。
- /// 资源在项目中的相对路径。
- /// 成功加载的资源对象;若路径无效或加载失败则返回null。
- public T? LoadResource(string path) where T : Resource
- {
- if (string.IsNullOrEmpty(path))
- return null;
-
- if (_loadedResources.TryGetValue(path, out var cached))
- return cached as T;
-
- var res = GD.Load(path);
- if (res == null)
- {
- GD.PrintErr($"[ResourceLoadSystem] Load failed: {path}");
- return null;
- }
-
- _loadedResources[path] = res;
- return res;
- }
+ private readonly Dictionary> _sceneLoaders = new();
///
- /// 获取一个场景的懒加载器,用于按需加载PackedScene资源。
- /// 若对应路径尚未注册加载器,则会自动创建一个新的Lazy实例。
- ///
- /// 场景文件的相对路径。
- /// 表示该场景懒加载逻辑的Lazy<PackedScene>对象。
- public Lazy GetSceneLoader(string path)
- {
- if (_sceneLoaders.TryGetValue(path, out var loader))
- return loader;
-
- loader = new Lazy(() =>
- {
- var scene = LoadResource(path);
- return scene ?? throw new InvalidOperationException($"Failed to load scene: {path}");
- });
-
- _sceneLoaders[path] = loader;
- return loader;
- }
-
- #endregion
-
- ///
- /// 根据给定路径加载场景,并创建其节点实例。
+ /// 根据给定路径加载场景,并创建其节点实例。
///
/// 期望返回的节点类型,必须是Node的子类。
/// 场景文件的相对路径。
@@ -159,10 +102,68 @@ public class ResourceLoadSystem : AbstractSystem, IResourceLoadSystem
_resourceFactories[path] = factory;
return factory;
}
+
+ ///
+ /// 初始化方法,在系统初始化时打印日志信息。
+ ///
+ protected override void OnInit()
+ {
+ }
+
+ #region 基础加载
+
+ ///
+ /// 加载指定类型的资源并进行缓存。如果资源已经加载过则直接从缓存中返回。
+ ///
+ /// 要加载的资源类型,必须继承自Resource。
+ /// 资源在项目中的相对路径。
+ /// 成功加载的资源对象;若路径无效或加载失败则返回null。
+ public T? LoadResource(string path) where T : Resource
+ {
+ if (string.IsNullOrEmpty(path))
+ return null;
+
+ if (_loadedResources.TryGetValue(path, out var cached))
+ return cached as T;
+
+ var res = GD.Load(path);
+ if (res == null)
+ {
+ GD.PrintErr($"[ResourceLoadSystem] Load failed: {path}");
+ return null;
+ }
+
+ _loadedResources[path] = res;
+ return res;
+ }
+
+ ///
+ /// 获取一个场景的懒加载器,用于按需加载PackedScene资源。
+ /// 若对应路径尚未注册加载器,则会自动创建一个新的Lazy实例。
+ ///
+ /// 场景文件的相对路径。
+ /// 表示该场景懒加载逻辑的Lazy<PackedScene>对象。
+ public Lazy GetSceneLoader(string path)
+ {
+ if (_sceneLoaders.TryGetValue(path, out var loader))
+ return loader;
+
+ loader = new Lazy(() =>
+ {
+ var scene = LoadResource(path);
+ return scene ?? throw new InvalidOperationException($"Failed to load scene: {path}");
+ });
+
+ _sceneLoaders[path] = loader;
+ return loader;
+ }
+
+ #endregion
+
#region 缓存管理
///
- /// 预加载一组资源和场景到内存中以提升后续访问速度。
+ /// 预加载一组资源和场景到内存中以提升后续访问速度。
///
/// 待预加载的资源路径集合。
public void Preload(IEnumerable paths)
@@ -175,7 +176,7 @@ public class ResourceLoadSystem : AbstractSystem, IResourceLoadSystem
}
///
- /// 清除指定路径的所有相关缓存数据,包括资源、场景加载器及各类工厂。
+ /// 清除指定路径的所有相关缓存数据,包括资源、场景加载器及各类工厂。
///
/// 要卸载的资源路径。
public void Unload(string path)
@@ -187,7 +188,7 @@ public class ResourceLoadSystem : AbstractSystem, IResourceLoadSystem
}
///
- /// 清空所有当前系统的资源缓存、加载器和工厂列表。
+ /// 清空所有当前系统的资源缓存、加载器和工厂列表。
///
public void ClearAll()
{
@@ -198,4 +199,4 @@ public class ResourceLoadSystem : AbstractSystem, IResourceLoadSystem
}
#endregion
-}
+}
\ No newline at end of file
diff --git a/GFramework.Godot/extensions/NodeExtensions.cs b/GFramework.Godot/extensions/NodeExtensions.cs
index 13737d9..b45a82f 100644
--- a/GFramework.Godot/extensions/NodeExtensions.cs
+++ b/GFramework.Godot/extensions/NodeExtensions.cs
@@ -243,7 +243,7 @@ public static class NodeExtensions
///
- /// 将指定节点转换为目标类型T
+ /// 将指定节点转换为目标类型T
///
/// 目标节点类型,必须继承自Node
/// 要转换的节点对象,可以为null
@@ -252,10 +252,8 @@ public static class NodeExtensions
public static T OfType(this Node? node) where T : Node
{
// 检查节点是否有效且类型匹配
- if (node.IsValidNode()&& node is T t)
+ if (node.IsValidNode() && node is T t)
return t;
throw new InvalidCastException($"Cannot cast {node} to {typeof(T)}");
}
-
-
}
\ No newline at end of file
diff --git a/GFramework.Godot/logging/GodotLogger.cs b/GFramework.Godot/logging/GodotLogger.cs
index cf20e97..3241c88 100644
--- a/GFramework.Godot/logging/GodotLogger.cs
+++ b/GFramework.Godot/logging/GodotLogger.cs
@@ -4,21 +4,18 @@ using Godot;
namespace GFramework.Godot.logging;
///
-/// Godot平台的日志记录器实现
+/// Godot平台的日志记录器实现
///
public sealed class GodotLogger(
string? name = null,
- LogLevel minLevel = LogLevel.Info) : AbstractLogger(name??ILogger.RootLoggerName, minLevel)
+ LogLevel minLevel = LogLevel.Info) : AbstractLogger(name ?? ILogger.RootLoggerName, minLevel)
{
protected override void Write(LogLevel level, string message, Exception? exception)
{
var prefix = $"[{level.ToString().ToUpper()}][{Name()}]";
// 将异常信息追加到日志消息中
- if (exception != null)
- {
- message += "\n" + exception;
- }
+ if (exception != null) message += "\n" + exception;
// 根据日志级别选择不同的输出方法
switch (level)
diff --git a/GFramework.Godot/logging/GodotLoggerFactory.cs b/GFramework.Godot/logging/GodotLoggerFactory.cs
index 2694db4..20e7565 100644
--- a/GFramework.Godot/logging/GodotLoggerFactory.cs
+++ b/GFramework.Godot/logging/GodotLoggerFactory.cs
@@ -3,12 +3,12 @@
namespace GFramework.Godot.logging;
///
-/// Godot日志工厂类,用于创建Godot平台专用的日志记录器实例
+/// Godot日志工厂类,用于创建Godot平台专用的日志记录器实例
///
-public class GodotLoggerFactory: ILoggerFactory
+public class GodotLoggerFactory : ILoggerFactory
{
///
- /// 获取指定名称的日志记录器实例
+ /// 获取指定名称的日志记录器实例
///
/// 日志记录器的名称
/// 返回GodotLogger类型的日志记录器实例
@@ -16,4 +16,4 @@ public class GodotLoggerFactory: ILoggerFactory
{
return new GodotLogger(name);
}
-}
+}
\ No newline at end of file
diff --git a/GFramework.Godot/system/AbstractAudioManagerSystem.cs b/GFramework.Godot/system/AbstractAudioManagerSystem.cs
index 7504f49..514a870 100644
--- a/GFramework.Godot/system/AbstractAudioManagerSystem.cs
+++ b/GFramework.Godot/system/AbstractAudioManagerSystem.cs
@@ -5,102 +5,427 @@ using Godot;
namespace GFramework.Godot.system;
///
-/// 音频管理器抽象基类,提供音频播放的基础实现
+/// 音频管理器抽象基类,提供音频播放的基础实现
///
public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManagerSystem
{
///
- /// 音频资源加载系统依赖
- ///
- protected IResourceLoadSystem? ResourceLoadSystem;
-
- ///
- /// 资源目录系统依赖
- ///
- protected IAssetCatalogSystem? AssetCatalogSystem;
-
- ///
- /// 背景音乐播放器
- ///
- protected AudioStreamPlayer? MusicPlayer;
-
- ///
- /// 音效播放器列表
- ///
- protected readonly List SoundPlayers = [];
-
- ///
- /// 可用音效播放器队列
- ///
- protected readonly Queue AvailableSoundPlayers = new();
-
- ///
- /// 3D音效播放器列表
- ///
- protected readonly List Sound3DPlayers = [];
-
- ///
- /// 可用3D音效播放器队列
- ///
- protected readonly Queue AvailableSound3DPlayers = new();
-
- ///
- /// 资源工厂系统依赖
- ///
- protected IResourceFactorySystem? ResourceFactorySystem;
-
- ///
- /// 背景音乐音量
- ///
- protected float MusicVolume = 1.0f;
-
- ///
- /// 音效音量
- ///
- protected float SoundVolume = 1.0f;
-
- ///
- /// 主音量
- ///
- protected float MasterVolume = 1.0f;
-
- ///
- /// 特效音量
- ///
- protected float SfxVolume = 1.0f;
-
- ///
- /// 语音音量
- ///
- protected float VoiceVolume = 1.0f;
-
- ///
- /// 环境音量
- ///
- protected float AmbientVolume = 1.0f;
-
- ///
- /// 音乐淡入淡出动画
- ///
- protected Tween? MusicFadeTween;
-
- ///
- /// 最大同时播放的音效数量
+ /// 最大同时播放的音效数量
///
protected const int MaxSoundPlayers = 10;
-
+
///
- /// 最大同时播放的3D音效数量
+ /// 最大同时播放的3D音效数量
///
protected const int MaxSound3DPlayers = 5;
///
- /// 所有者节点的抽象属性
+ /// 可用3D音效播放器队列
+ ///
+ protected readonly Queue AvailableSound3DPlayers = new();
+
+ ///
+ /// 可用音效播放器队列
+ ///
+ protected readonly Queue AvailableSoundPlayers = new();
+
+ ///
+ /// 3D音效播放器列表
+ ///
+ protected readonly List Sound3DPlayers = [];
+
+ ///
+ /// 音效播放器列表
+ ///
+ protected readonly List SoundPlayers = [];
+
+ ///
+ /// 环境音量
+ ///
+ protected float AmbientVolume = 1.0f;
+
+ ///
+ /// 资源目录系统依赖
+ ///
+ protected IAssetCatalogSystem? AssetCatalogSystem;
+
+ ///
+ /// 主音量
+ ///
+ protected float MasterVolume = 1.0f;
+
+ ///
+ /// 音乐淡入淡出动画
+ ///
+ protected Tween? MusicFadeTween;
+
+ ///
+ /// 背景音乐播放器
+ ///
+ protected AudioStreamPlayer? MusicPlayer;
+
+ ///
+ /// 背景音乐音量
+ ///
+ protected float MusicVolume = 1.0f;
+
+ ///
+ /// 资源工厂系统依赖
+ ///
+ protected IResourceFactorySystem? ResourceFactorySystem;
+
+ ///
+ /// 音频资源加载系统依赖
+ ///
+ protected IResourceLoadSystem? ResourceLoadSystem;
+
+ ///
+ /// 特效音量
+ ///
+ protected float SfxVolume = 1.0f;
+
+ ///
+ /// 音效音量
+ ///
+ protected float SoundVolume = 1.0f;
+
+ ///
+ /// 语音音量
+ ///
+ protected float VoiceVolume = 1.0f;
+
+ ///
+ /// 所有者节点的抽象属性
///
protected abstract Node Owner { get; }
///
- /// 系统初始化方法
+ /// 播放背景音乐
+ ///
+ /// 音频文件路径
+ /// 音量大小,范围0-1
+ /// 是否循环播放
+ public virtual void PlayMusic(string audioPath, float volume = 1.0f, bool loop = true)
+ {
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null || MusicPlayer == null) return;
+
+ // 停止当前正在进行的淡入淡出效果
+ MusicFadeTween?.Kill();
+
+ MusicPlayer.Stream = audioStream;
+ MusicPlayer.VolumeDb = LinearToDb(volume * MusicVolume * MasterVolume);
+ MusicPlayer.Play();
+ }
+
+ ///
+ /// 播放音效
+ ///
+ /// 音频文件路径
+ /// 音量大小,范围0-1
+ /// 音调调整
+ public virtual void PlaySound(string audioPath, float volume = 1.0f, float pitch = 1.0f)
+ {
+ if (AvailableSoundPlayers.Count == 0) return;
+
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null) return;
+
+ var player = AvailableSoundPlayers.Dequeue();
+ player.Stream = audioStream;
+ player.VolumeDb = LinearToDb(volume * SoundVolume * MasterVolume);
+ player.Play();
+ }
+
+ ///
+ /// 播放特效音效
+ ///
+ /// 音频文件路径
+ /// 音量大小,范围0-1
+ /// 音调调整
+ public virtual void PlaySfx(string audioPath, float volume = 1.0f, float pitch = 1.0f)
+ {
+ if (AvailableSoundPlayers.Count == 0) return;
+
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null) return;
+
+ var player = AvailableSoundPlayers.Dequeue();
+ player.Stream = audioStream;
+ player.VolumeDb = LinearToDb(volume * SfxVolume * MasterVolume);
+ player.Play();
+ }
+
+ ///
+ /// 播放语音
+ ///
+ /// 音频文件路径
+ /// 音量大小,范围0-1
+ /// 音调调整
+ public virtual void PlayVoice(string audioPath, float volume = 1.0f, float pitch = 1.0f)
+ {
+ if (AvailableSoundPlayers.Count == 0) return;
+
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null) return;
+
+ var player = AvailableSoundPlayers.Dequeue();
+ player.Stream = audioStream;
+ player.VolumeDb = LinearToDb(volume * VoiceVolume * MasterVolume);
+ player.Play();
+ }
+
+ ///
+ /// 播放环境音效
+ ///
+ /// 音频文件路径
+ /// 音量大小,范围0-1
+ /// 音调调整
+ public virtual void PlayAmbient(string audioPath, float volume = 1.0f, float pitch = 1.0f)
+ {
+ if (AvailableSoundPlayers.Count == 0) return;
+
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null) return;
+
+ var player = AvailableSoundPlayers.Dequeue();
+ player.Stream = audioStream;
+ player.VolumeDb = LinearToDb(volume * AmbientVolume * MasterVolume);
+ player.Play();
+ }
+
+ ///
+ /// 播放3D音效
+ ///
+ /// 音频文件路径
+ /// 3D空间中的位置
+ /// 音量大小,范围0-1
+ public virtual void PlaySound3D(string audioPath, Vector3 position, float volume = 1.0f)
+ {
+ if (AvailableSound3DPlayers.Count == 0) return;
+
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null) return;
+
+ var player = AvailableSound3DPlayers.Dequeue();
+ player.Stream = audioStream;
+ player.VolumeDb = LinearToDb(volume * SoundVolume * MasterVolume);
+ player.Position = position;
+ player.Play();
+ }
+
+ ///
+ /// 停止背景音乐
+ ///
+ public virtual void StopMusic()
+ {
+ MusicFadeTween?.Kill();
+ MusicPlayer?.Stop();
+ }
+
+ ///
+ /// 暂停背景音乐
+ ///
+ public virtual void PauseMusic()
+ {
+ MusicFadeTween?.Kill();
+ // todo 需要记录音乐播放位置,以便恢复播放时从正确位置开始
+ }
+
+ ///
+ /// 恢复背景音乐播放
+ ///
+ public virtual void ResumeMusic()
+ {
+ MusicPlayer?.Play();
+ }
+
+ ///
+ /// 设置背景音乐音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetMusicVolume(float volume)
+ {
+ MusicVolume = volume;
+ if (MusicPlayer != null) MusicPlayer.VolumeDb = LinearToDb(MusicVolume * MasterVolume);
+ }
+
+ ///
+ /// 获取背景音乐音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetMusicVolume()
+ {
+ return MusicVolume;
+ }
+
+ ///
+ /// 设置音效音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetSoundVolume(float volume)
+ {
+ SoundVolume = volume;
+ }
+
+ ///
+ /// 获取音效音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetSoundVolume()
+ {
+ return SoundVolume;
+ }
+
+ ///
+ /// 设置主音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetMasterVolume(float volume)
+ {
+ MasterVolume = volume;
+
+ // 更新音乐音量
+ if (MusicPlayer != null) MusicPlayer.VolumeDb = LinearToDb(MusicVolume * MasterVolume);
+ }
+
+ ///
+ /// 获取主音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetMasterVolume()
+ {
+ return MasterVolume;
+ }
+
+ ///
+ /// 设置SFX音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetSfxVolume(float volume)
+ {
+ SfxVolume = volume;
+ }
+
+ ///
+ /// 获取SFX音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetSfxVolume()
+ {
+ return SfxVolume;
+ }
+
+ ///
+ /// 设置语音音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetVoiceVolume(float volume)
+ {
+ VoiceVolume = volume;
+ }
+
+ ///
+ /// 获取语音音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetVoiceVolume()
+ {
+ return VoiceVolume;
+ }
+
+ ///
+ /// 设置环境音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual void SetAmbientVolume(float volume)
+ {
+ AmbientVolume = volume;
+ }
+
+ ///
+ /// 获取环境音量
+ ///
+ /// 音量大小,范围0-1
+ public virtual float GetAmbientVolume()
+ {
+ return AmbientVolume;
+ }
+
+ ///
+ /// 检查背景音乐是否正在播放
+ ///
+ /// 正在播放返回true,否则返回false
+ public virtual bool IsMusicPlaying()
+ {
+ return MusicPlayer?.Playing ?? false;
+ }
+
+ ///
+ /// 淡入背景音乐
+ ///
+ /// 音频文件路径
+ /// 淡入持续时间(秒)
+ /// 目标音量
+ public virtual void FadeInMusic(string audioPath, float duration, float volume = 1.0f)
+ {
+ var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
+ if (audioStream == null || MusicPlayer == null) return;
+
+ // 停止当前正在进行的淡入淡出效果
+ MusicFadeTween?.Kill();
+
+ MusicPlayer.Stream = audioStream;
+ MusicPlayer.VolumeDb = LinearToDb(0.0f); // 初始音量为0
+ MusicPlayer.Play();
+
+ // 创建淡入动画
+ MusicFadeTween = Owner.CreateTween();
+ MusicFadeTween.TweenProperty(MusicPlayer, "volume_db", LinearToDb(volume * MusicVolume * MasterVolume),
+ duration);
+ }
+
+ ///
+ /// 淡出背景音乐
+ ///
+ /// 淡出持续时间(秒)
+ public virtual void FadeOutMusic(float duration)
+ {
+ if (MusicPlayer == null) return;
+
+ // 停止当前正在进行的淡入淡出效果
+ MusicFadeTween?.Kill();
+
+ // 创建淡出动画
+ MusicFadeTween = Owner.CreateTween();
+ MusicFadeTween.TweenProperty(MusicPlayer, "volume_db", LinearToDb(0.0f), duration);
+ MusicFadeTween.TweenCallback(Callable.From(() => MusicPlayer.Stop()));
+ }
+
+ ///
+ /// 设置低通滤波器强度
+ ///
+ /// 滤波器强度,范围0-1
+ public virtual void SetLowPassFilter(float amount)
+ {
+ // TODO: 实现低通滤波器效果
+ // 可以通过AudioEffectLowPassFilter实现
+ }
+
+ ///
+ /// 设置音频混响效果
+ ///
+ /// 房间大小
+ /// 阻尼
+ /// 湿声级别
+ public virtual void SetReverb(float roomSize, float damping, float wetLevel)
+ {
+ // TODO: 实现音频混响效果
+ // 可以通过AudioEffectReverb实现
+ }
+
+ ///
+ /// 系统初始化方法
///
protected override void OnInit()
{
@@ -135,7 +460,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 当音效播放完成时的回调
+ /// 当音效播放完成时的回调
///
/// 完成播放的音频播放器
private void OnSoundFinished(AudioStreamPlayer player)
@@ -145,7 +470,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 当3D音效播放完成时的回调
+ /// 当3D音效播放完成时的回调
///
/// 完成播放的3D音频播放器
private void OnSound3DFinished(AudioStreamPlayer3D player)
@@ -155,26 +480,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 播放背景音乐
- ///
- /// 音频文件路径
- /// 音量大小,范围0-1
- /// 是否循环播放
- public virtual void PlayMusic(string audioPath, float volume = 1.0f, bool loop = true)
- {
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null || MusicPlayer == null) return;
-
- // 停止当前正在进行的淡入淡出效果
- MusicFadeTween?.Kill();
-
- MusicPlayer.Stream = audioStream;
- MusicPlayer.VolumeDb = LinearToDb(volume * MusicVolume * MasterVolume);
- MusicPlayer.Play();
- }
-
- ///
- /// 通过资源ID播放背景音乐
+ /// 通过资源ID播放背景音乐
///
/// 音乐资源ID
/// 音量大小,范围0-1
@@ -185,83 +491,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 播放音效
- ///
- /// 音频文件路径
- /// 音量大小,范围0-1
- /// 音调调整
- public virtual void PlaySound(string audioPath, float volume = 1.0f, float pitch = 1.0f)
- {
- if (AvailableSoundPlayers.Count == 0) return;
-
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null) return;
-
- var player = AvailableSoundPlayers.Dequeue();
- player.Stream = audioStream;
- player.VolumeDb = LinearToDb(volume * SoundVolume * MasterVolume);
- player.Play();
- }
-
- ///
- /// 播放特效音效
- ///
- /// 音频文件路径
- /// 音量大小,范围0-1
- /// 音调调整
- public virtual void PlaySfx(string audioPath, float volume = 1.0f, float pitch = 1.0f)
- {
- if (AvailableSoundPlayers.Count == 0) return;
-
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null) return;
-
- var player = AvailableSoundPlayers.Dequeue();
- player.Stream = audioStream;
- player.VolumeDb = LinearToDb(volume * SfxVolume * MasterVolume);
- player.Play();
- }
-
- ///
- /// 播放语音
- ///
- /// 音频文件路径
- /// 音量大小,范围0-1
- /// 音调调整
- public virtual void PlayVoice(string audioPath, float volume = 1.0f, float pitch = 1.0f)
- {
- if (AvailableSoundPlayers.Count == 0) return;
-
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null) return;
-
- var player = AvailableSoundPlayers.Dequeue();
- player.Stream = audioStream;
- player.VolumeDb = LinearToDb(volume * VoiceVolume * MasterVolume);
- player.Play();
- }
-
- ///
- /// 播放环境音效
- ///
- /// 音频文件路径
- /// 音量大小,范围0-1
- /// 音调调整
- public virtual void PlayAmbient(string audioPath, float volume = 1.0f, float pitch = 1.0f)
- {
- if (AvailableSoundPlayers.Count == 0) return;
-
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null) return;
-
- var player = AvailableSoundPlayers.Dequeue();
- player.Stream = audioStream;
- player.VolumeDb = LinearToDb(volume * AmbientVolume * MasterVolume);
- player.Play();
- }
-
- ///
- /// 通过资源ID播放音效
+ /// 通过资源ID播放音效
///
/// 音效资源ID
/// 音量大小,范围0-1
@@ -272,243 +502,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 播放3D音效
- ///
- /// 音频文件路径
- /// 3D空间中的位置
- /// 音量大小,范围0-1
- public virtual void PlaySound3D(string audioPath, Vector3 position, float volume = 1.0f)
- {
- if (AvailableSound3DPlayers.Count == 0) return;
-
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null) return;
-
- var player = AvailableSound3DPlayers.Dequeue();
- player.Stream = audioStream;
- player.VolumeDb = LinearToDb(volume * SoundVolume * MasterVolume);
- player.Position = position;
- player.Play();
- }
-
- ///
- /// 停止背景音乐
- ///
- public virtual void StopMusic()
- {
- MusicFadeTween?.Kill();
- MusicPlayer?.Stop();
- }
-
- ///
- /// 暂停背景音乐
- ///
- public virtual void PauseMusic()
- {
- MusicFadeTween?.Kill();
- // todo 需要记录音乐播放位置,以便恢复播放时从正确位置开始
- }
-
- ///
- /// 恢复背景音乐播放
- ///
- public virtual void ResumeMusic()
- {
- MusicPlayer?.Play();
- }
-
- ///
- /// 设置背景音乐音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetMusicVolume(float volume)
- {
- MusicVolume = volume;
- if (MusicPlayer != null)
- {
- MusicPlayer.VolumeDb = LinearToDb(MusicVolume * MasterVolume);
- }
- }
-
- ///
- /// 获取背景音乐音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetMusicVolume()
- {
- return MusicVolume;
- }
-
- ///
- /// 设置音效音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetSoundVolume(float volume)
- {
- SoundVolume = volume;
- }
-
- ///
- /// 获取音效音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetSoundVolume()
- {
- return SoundVolume;
- }
-
- ///
- /// 设置主音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetMasterVolume(float volume)
- {
- MasterVolume = volume;
-
- // 更新音乐音量
- if (MusicPlayer != null)
- {
- MusicPlayer.VolumeDb = LinearToDb(MusicVolume * MasterVolume);
- }
- }
-
- ///
- /// 获取主音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetMasterVolume()
- {
- return MasterVolume;
- }
-
- ///
- /// 设置SFX音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetSfxVolume(float volume)
- {
- SfxVolume = volume;
- }
-
- ///
- /// 获取SFX音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetSfxVolume()
- {
- return SfxVolume;
- }
-
- ///
- /// 设置语音音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetVoiceVolume(float volume)
- {
- VoiceVolume = volume;
- }
-
- ///
- /// 获取语音音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetVoiceVolume()
- {
- return VoiceVolume;
- }
-
- ///
- /// 设置环境音量
- ///
- /// 音量大小,范围0-1
- public virtual void SetAmbientVolume(float volume)
- {
- AmbientVolume = volume;
- }
-
- ///
- /// 获取环境音量
- ///
- /// 音量大小,范围0-1
- public virtual float GetAmbientVolume()
- {
- return AmbientVolume;
- }
-
- ///
- /// 检查背景音乐是否正在播放
- ///
- /// 正在播放返回true,否则返回false
- public virtual bool IsMusicPlaying()
- {
- return MusicPlayer?.Playing ?? false;
- }
-
- ///
- /// 淡入背景音乐
- ///
- /// 音频文件路径
- /// 淡入持续时间(秒)
- /// 目标音量
- public virtual void FadeInMusic(string audioPath, float duration, float volume = 1.0f)
- {
- var audioStream = ResourceLoadSystem?.LoadResource(audioPath);
- if (audioStream == null || MusicPlayer == null) return;
-
- // 停止当前正在进行的淡入淡出效果
- MusicFadeTween?.Kill();
-
- MusicPlayer.Stream = audioStream;
- MusicPlayer.VolumeDb = LinearToDb(0.0f); // 初始音量为0
- MusicPlayer.Play();
-
- // 创建淡入动画
- MusicFadeTween = Owner.CreateTween();
- MusicFadeTween.TweenProperty(MusicPlayer, "volume_db", LinearToDb(volume * MusicVolume * MasterVolume),
- duration);
- }
-
- ///
- /// 淡出背景音乐
- ///
- /// 淡出持续时间(秒)
- public virtual void FadeOutMusic(float duration)
- {
- if (MusicPlayer == null) return;
-
- // 停止当前正在进行的淡入淡出效果
- MusicFadeTween?.Kill();
-
- // 创建淡出动画
- MusicFadeTween = Owner.CreateTween();
- MusicFadeTween.TweenProperty(MusicPlayer, "volume_db", LinearToDb(0.0f), duration);
- MusicFadeTween.TweenCallback(Callable.From(() => MusicPlayer.Stop()));
- }
-
- ///
- /// 设置低通滤波器强度
- ///
- /// 滤波器强度,范围0-1
- public virtual void SetLowPassFilter(float amount)
- {
- // TODO: 实现低通滤波器效果
- // 可以通过AudioEffectLowPassFilter实现
- }
-
- ///
- /// 设置音频混响效果
- ///
- /// 房间大小
- /// 阻尼
- /// 湿声级别
- public virtual void SetReverb(float roomSize, float damping, float wetLevel)
- {
- // TODO: 实现音频混响效果
- // 可以通过AudioEffectReverb实现
- }
-
- ///
- /// 将线性音量值转换为分贝值
+ /// 将线性音量值转换为分贝值
///
/// 线性音量值(0-1)
/// 分贝值
@@ -518,7 +512,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 将分贝值转换为线性音量值
+ /// 将分贝值转换为线性音量值
///
/// 分贝值
/// 线性音量值(0-1)
@@ -528,7 +522,7 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
}
///
- /// 系统销毁时清理资源
+ /// 系统销毁时清理资源
///
protected override void OnDestroy()
{
@@ -539,16 +533,10 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
MusicPlayer?.QueueFree();
// 清理音效播放器池
- foreach (var player in SoundPlayers)
- {
- player.QueueFree();
- }
+ foreach (var player in SoundPlayers) player.QueueFree();
// 清理3D音效播放器池
- foreach (var player in Sound3DPlayers)
- {
- player.QueueFree();
- }
+ foreach (var player in Sound3DPlayers) player.QueueFree();
SoundPlayers.Clear();
AvailableSoundPlayers.Clear();
diff --git a/GFramework.Godot/system/IAudioManagerSystem.cs b/GFramework.Godot/system/IAudioManagerSystem.cs
index e035bc2..e9c9c35 100644
--- a/GFramework.Godot/system/IAudioManagerSystem.cs
+++ b/GFramework.Godot/system/IAudioManagerSystem.cs
@@ -4,173 +4,173 @@ using Godot;
namespace GFramework.Godot.system;
///
-/// 音频管理器系统接口,用于统一管理背景音乐和音效的播放
+/// 音频管理器系统接口,用于统一管理背景音乐和音效的播放
///
public interface IAudioManagerSystem : ISystem
{
///
- /// 播放背景音乐
+ /// 播放背景音乐
///
/// 音频文件路径
/// 音量大小,范围0-1
/// 是否循环播放
void PlayMusic(string audioPath, float volume = 1.0f, bool loop = true);
-
+
///
- /// 播放音效
+ /// 播放音效
///
/// 音频文件路径
/// 音量大小,范围0-1
/// 音调调整
void PlaySound(string audioPath, float volume = 1.0f, float pitch = 1.0f);
-
+
///
- /// 播放特效音效
+ /// 播放特效音效
///
/// 音频文件路径
/// 音量大小,范围0-1
/// 音调调整
void PlaySfx(string audioPath, float volume = 1.0f, float pitch = 1.0f);
-
+
///
- /// 播放语音
+ /// 播放语音
///
/// 音频文件路径
/// 音量大小,范围0-1
/// 音调调整
void PlayVoice(string audioPath, float volume = 1.0f, float pitch = 1.0f);
-
+
///
- /// 播放环境音效
+ /// 播放环境音效
///
/// 音频文件路径
/// 音量大小,范围0-1
/// 音调调整
void PlayAmbient(string audioPath, float volume = 1.0f, float pitch = 1.0f);
-
+
///
- /// 停止背景音乐
+ /// 停止背景音乐
///
void StopMusic();
-
+
///
- /// 暂停背景音乐
+ /// 暂停背景音乐
///
void PauseMusic();
-
+
///
- /// 恢复背景音乐播放
+ /// 恢复背景音乐播放
///
void ResumeMusic();
-
+
///
- /// 设置背景音乐音量
+ /// 设置背景音乐音量
///
/// 音量大小,范围0-1
void SetMusicVolume(float volume);
-
+
///
- /// 获取背景音乐音量
+ /// 获取背景音乐音量
///
/// 音量大小,范围0-1
float GetMusicVolume();
-
+
///
- /// 设置音效音量
+ /// 设置音效音量
///
/// 音量大小,范围0-1
void SetSoundVolume(float volume);
-
+
///
- /// 获取音效音量
+ /// 获取音效音量
///
/// 音量大小,范围0-1
float GetSoundVolume();
-
+
///
- /// 设置特效音量
+ /// 设置特效音量
///
/// 音量大小,范围0-1
void SetSfxVolume(float volume);
-
+
///
- /// 获取特效音量
+ /// 获取特效音量
///
/// 音量大小,范围0-1
float GetSfxVolume();
-
+
///
- /// 设置语音音量
+ /// 设置语音音量
///
/// 音量大小,范围0-1
void SetVoiceVolume(float volume);
-
+
///
- /// 获取语音音量
+ /// 获取语音音量
///
/// 音量大小,范围0-1
float GetVoiceVolume();
-
+
///
- /// 设置环境音量
+ /// 设置环境音量
///
/// 音量大小,范围0-1
void SetAmbientVolume(float volume);
-
+
///
- /// 获取环境音量
+ /// 获取环境音量
///
/// 音量大小,范围0-1
float GetAmbientVolume();
-
+
///
- /// 设置主音量
+ /// 设置主音量
///
/// 音量大小,范围0-1
void SetMasterVolume(float volume);
-
+
///
- /// 获取主音量
+ /// 获取主音量
///
/// 音量大小,范围0-1
float GetMasterVolume();
-
+
///
- /// 检查背景音乐是否正在播放
+ /// 检查背景音乐是否正在播放
///
/// 正在播放返回true,否则返回false
bool IsMusicPlaying();
-
+
///
- /// 淡入背景音乐
+ /// 淡入背景音乐
///
/// 音频文件路径
/// 淡入持续时间(秒)
/// 目标音量
void FadeInMusic(string audioPath, float duration, float volume = 1.0f);
-
+
///
- /// 淡出背景音乐
+ /// 淡出背景音乐
///
/// 淡出持续时间(秒)
void FadeOutMusic(float duration);
-
+
///
- /// 播放3D音效
+ /// 播放3D音效
///
/// 音频文件路径
/// 3D空间中的位置
/// 音量大小,范围0-1
void PlaySound3D(string audioPath, Vector3 position, float volume = 1.0f);
-
+
///
- /// 设置低通滤波器强度
+ /// 设置低通滤波器强度
///
/// 滤波器强度,范围0-1
void SetLowPassFilter(float amount);
-
+
///
- /// 设置音频混响效果
+ /// 设置音频混响效果
///
/// 房间大小
/// 阻尼
diff --git a/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj b/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj
index 698a56e..5ec19a5 100644
--- a/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj
+++ b/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj
@@ -6,6 +6,6 @@
10
-
+
diff --git a/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs b/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs
index 8799cfa..1e388ca 100644
--- a/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs
+++ b/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs
@@ -1,21 +1,20 @@
using System;
-namespace GFramework.SourceGenerators.Attributes.enums
+namespace GFramework.SourceGenerators.Attributes.enums;
+
+///
+/// 标注在 enum 上,Source Generator 会为该 enum 生成扩展方法。
+///
+[AttributeUsage(AttributeTargets.Enum)]
+public sealed class GenerateEnumExtensionsAttribute : Attribute
{
///
- /// 标注在 enum 上,Source Generator 会为该 enum 生成扩展方法。
+ /// 是否为每个枚举项生成单独的 IsXXX 方法(默认 true)。
///
- [AttributeUsage(AttributeTargets.Enum)]
- public sealed class GenerateEnumExtensionsAttribute : Attribute
- {
- ///
- /// 是否为每个枚举项生成单独的 IsXXX 方法(默认 true)。
- ///
- public bool GenerateIsMethods { get; set; } = true;
+ public bool GenerateIsMethods { get; set; } = true;
- ///
- /// 是否生成一个 IsIn(params T[]) 方法以简化多值判断(默认 true)。
- ///
- public bool GenerateIsInMethod { get; set; } = true;
- }
+ ///
+ /// 是否生成一个 IsIn(params T[]) 方法以简化多值判断(默认 true)。
+ ///
+ public bool GenerateIsInMethod { get; set; } = true;
}
\ No newline at end of file
diff --git a/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs b/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs
index aff9912..a38f0d3 100644
--- a/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs
+++ b/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs
@@ -4,7 +4,7 @@ using System;
namespace GFramework.SourceGenerators.Attributes.logging;
///
-/// 标注在类上,Source Generator 会为该类自动生成一个日志记录器字段。
+/// 标注在类上,Source Generator 会为该类自动生成一个日志记录器字段。
///
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class LogAttribute : Attribute
@@ -14,7 +14,7 @@ public sealed class LogAttribute : Attribute
}
///
- /// 初始化 GodotLogAttribute 类的新实例
+ /// 初始化 GodotLogAttribute 类的新实例
///
/// 日志分类名,默认使用类名
public LogAttribute(string? name)
diff --git a/GFramework.SourceGenerators/logging/Diagnostic.cs b/GFramework.SourceGenerators/logging/Diagnostic.cs
deleted file mode 100644
index 10aea63..0000000
--- a/GFramework.SourceGenerators/logging/Diagnostic.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using Microsoft.CodeAnalysis;
-
-namespace GFramework.SourceGenerators.logging;
-
-///
-/// 提供诊断描述符的静态类,用于GFramework日志生成器的编译时检查
-///
-internal static class LoggerDiagnostics
-{
- ///
- /// 定义诊断描述符:要求使用[Log]特性的类必须声明为partial
- ///
- ///
- /// 当类使用[Log]特性但未声明为partial时,编译器将报告此错误
- ///
- public static readonly DiagnosticDescriptor MustBePartial =
- new(
- id: "GFLOG001",
- title: "Class must be partial",
- messageFormat: "Class '{0}' must be declared partial to use [Log]",
- category: "GFramework.Logging",
- DiagnosticSeverity.Error,
- isEnabledByDefault: true
- );
-
- ///
- /// 定义诊断描述符:LogAttribute无法生成Logger的错误情况
- ///
- public static readonly DiagnosticDescriptor LogAttributeInvalid =
- new(
- id: "GFW_LOG001",
- title: "LogAttribute cannot generate Logger",
- messageFormat: "LogAttribute on class '{0}' is ineffective: {1}",
- category: "GFramework.Godot.Logging",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
-}
\ No newline at end of file
diff --git a/GFramework.SourceGenerators/logging/LoggerDiagnostic.cs b/GFramework.SourceGenerators/logging/LoggerDiagnostic.cs
new file mode 100644
index 0000000..8448556
--- /dev/null
+++ b/GFramework.SourceGenerators/logging/LoggerDiagnostic.cs
@@ -0,0 +1,37 @@
+using Microsoft.CodeAnalysis;
+
+namespace GFramework.SourceGenerators.logging;
+
+///
+/// 提供诊断描述符的静态类,用于GFramework日志生成器的编译时检查
+///
+internal static class LoggerDiagnostics
+{
+ ///
+ /// 定义诊断描述符:要求使用[Log]特性的类必须声明为partial
+ ///
+ ///
+ /// 当类使用[Log]特性但未声明为partial时,编译器将报告此错误
+ ///
+ public static readonly DiagnosticDescriptor MustBePartial =
+ new(
+ "GFLOG001",
+ "Class must be partial",
+ "Class '{0}' must be declared partial to use [Log]",
+ "GFramework.Logging",
+ DiagnosticSeverity.Error,
+ true
+ );
+
+ ///
+ /// 定义诊断描述符:LogAttribute无法生成Logger的错误情况
+ ///
+ public static readonly DiagnosticDescriptor LogAttributeInvalid =
+ new(
+ "GFW_LOG001",
+ "LogAttribute cannot generate Logger",
+ "LogAttribute on class '{0}' is ineffective: {1}",
+ "GFramework.Godot.Logging",
+ DiagnosticSeverity.Warning,
+ true);
+}
\ No newline at end of file
diff --git a/GFramework.SourceGenerators/logging/LoggerGenerator.cs b/GFramework.SourceGenerators/logging/LoggerGenerator.cs
index 20a0bcd..d4899d9 100644
--- a/GFramework.SourceGenerators/logging/LoggerGenerator.cs
+++ b/GFramework.SourceGenerators/logging/LoggerGenerator.cs
@@ -12,7 +12,7 @@ using Microsoft.CodeAnalysis.Text;
namespace GFramework.SourceGenerators.logging;
///
-/// 日志生成器,用于为标记了LogAttribute的类自动生成日志字段
+/// 日志生成器,用于为标记了LogAttribute的类自动生成日志字段
///
[Generator]
public sealed class LoggerGenerator : IIncrementalGenerator
@@ -22,7 +22,7 @@ public sealed class LoggerGenerator : IIncrementalGenerator
private const string AttributeShortNameWithoutSuffix = "Log";
///
- /// 初始化生成器,设置语法过滤和代码生成逻辑
+ /// 初始化生成器,设置语法过滤和代码生成逻辑
///
/// 增量生成器初始化上下文
public void Initialize(IncrementalGeneratorInitializationContext context)
@@ -87,7 +87,7 @@ public sealed class LoggerGenerator : IIncrementalGenerator
}
///
- /// 获取类符号上的LogAttribute特性
+ /// 获取类符号上的LogAttribute特性
///
/// 类符号
/// LogAttribute特性数据,如果不存在则返回null
@@ -105,7 +105,7 @@ public sealed class LoggerGenerator : IIncrementalGenerator
}
///
- /// 生成日志字段代码
+ /// 生成日志字段代码
///
/// 类符号
/// LogAttribute特性数据
@@ -160,7 +160,7 @@ public sealed class LoggerGenerator : IIncrementalGenerator
sb.AppendLine($" public partial class {className}");
sb.AppendLine(" {");
- sb.AppendLine($" /// Auto-generated logger");
+ sb.AppendLine(" /// Auto-generated logger");
sb.AppendLine(
$" {access} {staticKeyword}readonly ILogger {fieldName} = " +
$"new ConsoleLoggerFactory().GetLogger(\"{name}\");");
@@ -173,7 +173,7 @@ public sealed class LoggerGenerator : IIncrementalGenerator
}
///
- /// 从特性数据中获取命名参数的值
+ /// 从特性数据中获取命名参数的值
///
/// 特性数据
/// 参数名称
diff --git a/GFramework.csproj b/GFramework.csproj
index a9aa03e..5a873a8 100644
--- a/GFramework.csproj
+++ b/GFramework.csproj
@@ -20,10 +20,10 @@
-
-
-
-
+
+
+
+
GFramework.SorceGenerators\bin\Debug\netstandard2.0\GFramework.Generator.Attributes.dll
@@ -47,13 +47,13 @@
-
-
+
+
-
-
-
+
+
+
GFramework.SorceGenerators\enums\EnumExtensionsGenerator.cs
@@ -70,9 +70,9 @@
-
-
-
+
+
+