diff --git a/GFramework.Game.Abstractions/scene/SceneTransitionEvent.cs b/GFramework.Game.Abstractions/scene/SceneTransitionEvent.cs index 348bb6d..00b6517 100644 --- a/GFramework.Game.Abstractions/scene/SceneTransitionEvent.cs +++ b/GFramework.Game.Abstractions/scene/SceneTransitionEvent.cs @@ -21,7 +21,7 @@ namespace GFramework.Game.Abstractions.scene; /// public sealed class SceneTransitionEvent { - private readonly Dictionary _context = new(); + private readonly Dictionary _context = new(StringComparer.Ordinal); /// /// 获取或初始化源场景的唯一标识符。 diff --git a/GFramework.Game/data/DataRepository.cs b/GFramework.Game/data/DataRepository.cs index ccd3fd6..a02573e 100644 --- a/GFramework.Game/data/DataRepository.cs +++ b/GFramework.Game/data/DataRepository.cs @@ -120,6 +120,9 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options = this.SendEvent(new DataBatchSavedEvent(valueTuples)); } + /// + /// 初始化 + /// protected override void OnInit() { _storage ??= this.GetUtility()!; diff --git a/GFramework.Game/data/UnifiedSettingsDataRepository.cs b/GFramework.Game/data/UnifiedSettingsDataRepository.cs index 8a17e12..854561d 100644 --- a/GFramework.Game/data/UnifiedSettingsDataRepository.cs +++ b/GFramework.Game/data/UnifiedSettingsDataRepository.cs @@ -184,6 +184,9 @@ public class UnifiedSettingsDataRepository( _typeRegistry[location.Key] = type; } + /// + /// 初始化 + /// protected override void OnInit() { _storage ??= this.GetUtility()!; diff --git a/GFramework.Game/scene/SceneTransitionPipeline.cs b/GFramework.Game/scene/SceneTransitionPipeline.cs index f78594c..6332972 100644 --- a/GFramework.Game/scene/SceneTransitionPipeline.cs +++ b/GFramework.Game/scene/SceneTransitionPipeline.cs @@ -122,14 +122,15 @@ public class SceneTransitionPipeline { @event.Set("Phases", phases.ToString()); - Log.Debug( - "Execute pipeline: Phases={0}, From={1}, To={2}, Type={3}, HandlerCount={4}", - phases, - @event.FromSceneKey, - @event.ToSceneKey ?? "None", - @event.TransitionType, - _handlers.Count - ); + if (@event.FromSceneKey != null) + Log.Debug( + "Execute pipeline: Phases={0}, From={1}, To={2}, Type={3}, HandlerCount={4}", + phases, + @event.FromSceneKey, + @event.ToSceneKey ?? "None", + @event.TransitionType, + _handlers.Count + ); var sortedHandlers = FilterAndSortHandlers(@event, phases); diff --git a/GFramework.Game/scene/handler/LoadingProgressHandler.cs b/GFramework.Game/scene/handler/LoadingProgressHandler.cs deleted file mode 100644 index 95b33d8..0000000 --- a/GFramework.Game/scene/handler/LoadingProgressHandler.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2026 GeWuYou -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using GFramework.Core.Abstractions.logging; -using GFramework.Core.logging; -using GFramework.Game.Abstractions.enums; -using GFramework.Game.Abstractions.scene; - -namespace GFramework.Game.scene.handler; - -/// -/// 加载进度处理器,用于在场景加载前显示加载界面和进度反馈。 -/// -public sealed class LoadingProgressHandler : SceneTransitionHandlerBase -{ - private static readonly ILogger Log = LoggerFactoryResolver.Provider.CreateLogger(nameof(LoadingProgressHandler)); - - /// - /// 获取处理器优先级,数值越小优先级越高(优先执行)。 - /// - public override int Priority => -100; - - /// - /// 获取处理器处理的场景切换阶段,只处理 BeforeChange 阶段。 - /// - public override SceneTransitionPhases Phases => SceneTransitionPhases.BeforeChange; - - /// - /// 处理场景切换事件的异步方法。 - /// - /// 场景切换事件对象,包含切换的相关信息。 - /// 取消令牌,用于控制异步操作的取消。 - /// 表示异步操作的任务。 - public override async Task HandleAsync(SceneTransitionEvent @event, CancellationToken cancellationToken) - { - // 只处理 Push 和 Replace 操作(需要加载场景) - if (@event.TransitionType != SceneTransitionType.Push && - @event.TransitionType != SceneTransitionType.Replace) - return; - - // 显示加载界面 - // TODO: 调用 UI 系统显示加载界面 - Log.Info("Loading scene: {0}", @event.ToSceneKey); - - // 监听加载进度(如果需要) - // 这里可以通过事件上下文传递进度信息 - // 例如:@event.Set("LoadingProgress", progressValue); - - await Task.CompletedTask; - } -} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs b/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs index c77db89..5969c32 100644 --- a/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs +++ b/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs @@ -13,4 +13,8 @@ namespace GFramework.Game.setting.events; +/// +/// 表示所有设置已应用的事件。 +/// 此事件通常用于通知系统或组件,所有的设置配置已经完成并生效。 +/// public sealed class SettingsAppliedAllEvent; \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsInitializedEvent.cs b/GFramework.Game/setting/events/SettingsInitializedEvent.cs index 2974514..640db79 100644 --- a/GFramework.Game/setting/events/SettingsInitializedEvent.cs +++ b/GFramework.Game/setting/events/SettingsInitializedEvent.cs @@ -13,4 +13,8 @@ namespace GFramework.Game.setting.events; +/// +/// 表示设置已初始化的事件。 +/// 此事件用于通知系统或组件,所有设置已完成初始化。 +/// public sealed class SettingsInitializedEvent; \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsSavedAllEvent.cs b/GFramework.Game/setting/events/SettingsSavedAllEvent.cs index 7c0b151..18ccbd9 100644 --- a/GFramework.Game/setting/events/SettingsSavedAllEvent.cs +++ b/GFramework.Game/setting/events/SettingsSavedAllEvent.cs @@ -13,4 +13,8 @@ namespace GFramework.Game.setting.events; +/// +/// 表示所有设置已保存的事件。 +/// 此事件用于通知系统或组件,所有设置数据已成功保存。 +/// public sealed class SettingsSavedAllEvent; \ No newline at end of file diff --git a/GFramework.Godot/extensions/GodotPathExtensions.cs b/GFramework.Godot/extensions/GodotPathExtensions.cs index 755bf3f..1f81aa9 100644 --- a/GFramework.Godot/extensions/GodotPathExtensions.cs +++ b/GFramework.Godot/extensions/GodotPathExtensions.cs @@ -1,26 +1,36 @@ namespace GFramework.Godot.extensions; +/// +/// 提供对 Godot 路径相关操作的扩展方法。 +/// 包含判断路径类型的功能,例如用户数据路径(user://)和资源路径(res://)。 +/// public static class GodotPathExtensions { /// - /// 判断是否是 Godot 用户数据路径(user://) + /// 判断指定路径是否为 Godot 用户数据路径(user://)。 /// + /// 待检查的路径字符串。 + /// 如果路径以 "user://" 开头且不为空,则返回 true;否则返回 false。 public static bool IsUserPath(this string path) { return !string.IsNullOrEmpty(path) && path.StartsWith("user://"); } /// - /// 判断是否是 Godot 资源路径(res://) + /// 判断指定路径是否为 Godot 资源路径(res://)。 /// + /// 待检查的路径字符串。 + /// 如果路径以 "res://" 开头且不为空,则返回 true;否则返回 false。 public static bool IsResPath(this string path) { return !string.IsNullOrEmpty(path) && path.StartsWith("res://"); } /// - /// 判断是否是 Godot 特殊路径(user:// 或 res://) + /// 判断指定路径是否为 Godot 特殊路径(user:// 或 res://)。 /// + /// 待检查的路径字符串。 + /// 如果路径是用户数据路径或资源路径,则返回 true;否则返回 false。 public static bool IsGodotPath(this string path) { return path.IsUserPath() || path.IsResPath(); diff --git a/GFramework.Godot/logging/GodotLogger.cs b/GFramework.Godot/logging/GodotLogger.cs index c9c2895..ab1cc95 100644 --- a/GFramework.Godot/logging/GodotLogger.cs +++ b/GFramework.Godot/logging/GodotLogger.cs @@ -5,19 +5,31 @@ using Godot; namespace GFramework.Godot.logging; /// -/// Godot平台的日志记录器实现 +/// Godot平台的日志记录器实现。 +/// 该类继承自 ,用于在 Godot 引擎中输出日志信息。 +/// 支持不同日志级别的输出,并根据级别调用 Godot 的相应方法。 /// +/// 日志记录器的名称,默认为根日志记录器名称。 +/// 最低日志级别,默认为 。 public sealed class GodotLogger( string? name = null, LogLevel minLevel = LogLevel.Info) : AbstractLogger(name ?? RootLoggerName, minLevel) { + /// + /// 写入日志的核心方法。 + /// 格式化日志消息并根据日志级别调用 Godot 的输出方法。 + /// + /// 日志级别。 + /// 日志消息内容。 + /// 可选的异常信息。 protected override void Write(LogLevel level, string message, Exception? exception) { + // 构造时间戳和日志前缀 var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); var levelStr = level.ToString().ToUpper().PadRight(7); var logPrefix = $"[{timestamp}] {levelStr} [{Name()}]"; - // 添加异常信息 + // 添加异常信息到日志消息中 if (exception != null) message += "\n" + exception; var logMessage = $"{logPrefix} {message}"; diff --git a/GFramework.Godot/logging/GodotLoggerFactory.cs b/GFramework.Godot/logging/GodotLoggerFactory.cs index e8a8347..2d2a276 100644 --- a/GFramework.Godot/logging/GodotLoggerFactory.cs +++ b/GFramework.Godot/logging/GodotLoggerFactory.cs @@ -11,6 +11,7 @@ public class GodotLoggerFactory : ILoggerFactory /// 获取指定名称的日志记录器实例 /// /// 日志记录器的名称 + /// 日志记录器的最小日志级别 /// 返回GodotLogger类型的日志记录器实例 public ILogger GetLogger(string name, LogLevel minLevel = LogLevel.Info) { diff --git a/GFramework.Godot/scene/ControlSceneBehavior.cs b/GFramework.Godot/scene/ControlSceneBehavior.cs new file mode 100644 index 0000000..f62ec0e --- /dev/null +++ b/GFramework.Godot/scene/ControlSceneBehavior.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// Control 场景行为类,用于管理 UI 场景节点的生命周期。 +/// 适用于基于 Control 的 UI 场景元素。 +/// +public sealed class ControlSceneBehavior : SceneBehaviorBase +{ + /// + /// 初始化 ControlSceneBehavior 实例。 + /// + /// UI 场景节点的所有者实例。 + /// 场景的唯一标识键。 + public ControlSceneBehavior(Control owner, string key) + : base(owner, key) + { + } +} \ No newline at end of file diff --git a/GFramework.Godot/scene/GenericSceneBehavior.cs b/GFramework.Godot/scene/GenericSceneBehavior.cs new file mode 100644 index 0000000..c6269a7 --- /dev/null +++ b/GFramework.Godot/scene/GenericSceneBehavior.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// 通用场景行为类,用于管理任意 Node 类型场景节点的生命周期。 +/// 当场景节点不属于 Node2D、Node3D 或 Control 时使用此类。 +/// +public sealed class GenericSceneBehavior : SceneBehaviorBase +{ + /// + /// 初始化 GenericSceneBehavior 实例。 + /// + /// 场景节点的所有者实例。 + /// 场景的唯一标识键。 + public GenericSceneBehavior(Node owner, string key) + : base(owner, key) + { + } +} \ No newline at end of file diff --git a/GFramework.Godot/scene/GodotSceneFactory.cs b/GFramework.Godot/scene/GodotSceneFactory.cs new file mode 100644 index 0000000..c5c472a --- /dev/null +++ b/GFramework.Godot/scene/GodotSceneFactory.cs @@ -0,0 +1,74 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GFramework.Core.Abstractions.logging; +using GFramework.Core.extensions; +using GFramework.Core.logging; +using GFramework.Core.utility; +using GFramework.Game.Abstractions.scene; + +namespace GFramework.Godot.scene; + +/// +/// Godot 场景工厂类,用于创建场景实例。 +/// 继承自 AbstractContextUtility 并实现 ISceneFactory 接口。 +/// +public class GodotSceneFactory : AbstractContextUtility, ISceneFactory +{ + /// + /// 日志记录器,用于记录调试信息。 + /// + private static readonly ILogger Log = + LoggerFactoryResolver.Provider.CreateLogger(nameof(GodotSceneFactory)); + + /// + /// 场景注册表,用于管理场景资源。 + /// + private IGodotSceneRegistry _registry = null!; + + /// + /// 根据指定的场景键创建场景行为实例。 + /// + /// 场景的唯一标识符。 + /// 返回创建的场景行为实例。 + public ISceneBehavior Create(string sceneKey) + { + // 从注册表中获取指定场景键对应的 PackedScene + var scene = _registry.Get(sceneKey); + + // 实例化场景节点 + var node = scene.Instantiate(); + + // 检查节点是否实现了 ISceneBehaviorProvider 接口 + if (node is ISceneBehaviorProvider provider) + { + var behavior = provider.GetScene(); + Log.Debug("Created scene instance from provider: {0}", sceneKey); + return behavior; + } + + // 否则使用工厂自动创建 + var autoBehavior = SceneBehaviorFactory.Create(node, sceneKey); + Log.Debug("Created scene instance with auto factory: {0}", sceneKey); + return autoBehavior; + } + + /// + /// 初始化方法,在对象初始化时调用。 + /// 获取并设置场景注册表实例。 + /// + protected override void OnInit() + { + _registry = this.GetUtility()!; + } +} \ No newline at end of file diff --git a/GFramework.Godot/scene/Node2DSceneBehavior.cs b/GFramework.Godot/scene/Node2DSceneBehavior.cs new file mode 100644 index 0000000..77d9e6c --- /dev/null +++ b/GFramework.Godot/scene/Node2DSceneBehavior.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// Node2D 场景行为类,用于管理 2D 场景节点的生命周期。 +/// 适用于 Sprite2D、TileMap 等 2D 场景元素。 +/// +public sealed class Node2DSceneBehavior : SceneBehaviorBase +{ + /// + /// 初始化 Node2DSceneBehavior 实例。 + /// + /// 2D 场景节点的所有者实例。 + /// 场景的唯一标识键。 + public Node2DSceneBehavior(Node2D owner, string key) + : base(owner, key) + { + } +} \ No newline at end of file diff --git a/GFramework.Godot/scene/Node3DSceneBehavior.cs b/GFramework.Godot/scene/Node3DSceneBehavior.cs new file mode 100644 index 0000000..1d5e9e8 --- /dev/null +++ b/GFramework.Godot/scene/Node3DSceneBehavior.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// Node3D 场景行为类,用于管理 3D 场景节点的生命周期。 +/// 适用于 MeshInstance3D、Camera3D 等 3D 场景元素。 +/// +public sealed class Node3DSceneBehavior : SceneBehaviorBase +{ + /// + /// 初始化 Node3DSceneBehavior 实例。 + /// + /// 3D 场景节点的所有者实例。 + /// 场景的唯一标识键。 + public Node3DSceneBehavior(Node3D owner, string key) + : base(owner, key) + { + } +} \ No newline at end of file diff --git a/GFramework.Godot/scene/SceneBehaviorBase.cs b/GFramework.Godot/scene/SceneBehaviorBase.cs new file mode 100644 index 0000000..27dece3 --- /dev/null +++ b/GFramework.Godot/scene/SceneBehaviorBase.cs @@ -0,0 +1,203 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GFramework.Game.Abstractions.scene; +using GFramework.Godot.extensions; +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// 场景行为基类,封装通用的场景生命周期管理逻辑。 +/// 提供对 Node 类型场景节点的统一管理,包括加载、进入、暂停、恢复、退出、卸载等操作。 +/// +/// Node 类型的场景节点。 +public abstract class SceneBehaviorBase : ISceneBehavior + where T : Node +{ + /// + /// 场景的唯一标识键。 + /// + private readonly string _key; + + /// + /// IScene 接口引用(如果节点实现了该接口)。 + /// + private readonly IScene? _scene; + + /// + /// 场景节点的所有者实例。 + /// + protected readonly T Owner; + + /// + /// 场景是否处于活跃状态。 + /// + private bool _isActive; + + /// + /// 场景是否已加载。 + /// + private bool _isLoaded; + + /// + /// 场景是否正在过渡中。 + /// + private bool _isTransitioning; + + /// + /// 初始化 SceneBehaviorBase 实例。 + /// + /// 场景节点的所有者实例。 + /// 场景的唯一标识键。 + protected SceneBehaviorBase(T owner, string key) + { + Owner = owner; + _key = key; + _scene = owner as IScene; + } + + #region ISceneBehavior 实现 + + /// + /// 获取场景的唯一标识键。 + /// + public string Key => _key; + + /// + /// 获取场景是否已加载完成的状态。 + /// + public bool IsLoaded => _isLoaded; + + /// + /// 获取场景是否处于活跃运行状态。 + /// + public bool IsActive => _isActive; + + /// + /// 获取场景是否正在进行切换操作。 + /// + public bool IsTransitioning => _isTransitioning; + + /// + /// 获取场景节点是否有效。 + /// + public bool IsAlive => Owner.IsValidNode(); + + /// + /// 异步加载场景所需资源。 + /// 在场景正式进入前调用,负责预加载场景所需的各类资源。 + /// + /// 场景进入参数,可能包含初始化数据或上下文信息。 + /// 表示加载操作完成的ValueTask。 + public virtual async ValueTask OnLoadAsync(ISceneEnterParam? param) + { + _isTransitioning = true; + + // 调用可选接口 + if (_scene != null) + await _scene.OnLoadAsync(param); + + _isLoaded = true; + _isTransitioning = false; + } + + /// + /// 异步处理场景正式进入逻辑。 + /// 在资源加载完成后调用,启动场景的主要运行逻辑。 + /// + /// 表示进入操作完成的ValueTask。 + public virtual async ValueTask OnEnterAsync() + { + _isTransitioning = true; + + if (_scene != null) + await _scene.OnEnterAsync(); + + _isActive = true; + _isTransitioning = false; + } + + /// + /// 异步处理场景暂停逻辑。 + /// 当场景被其他场景覆盖或失去焦点时调用。 + /// + /// 表示暂停操作完成的ValueTask。 + public virtual async ValueTask OnPauseAsync() + { + if (_scene != null) + await _scene.OnPauseAsync(); + + // 暂停处理 + Owner.SetProcess(false); + Owner.SetPhysicsProcess(false); + Owner.SetProcessInput(false); + + _isActive = false; + } + + /// + /// 异步处理场景恢复逻辑。 + /// 当场景重新获得焦点或从暂停状态恢复时调用。 + /// + /// 表示恢复操作完成的ValueTask。 + public virtual async ValueTask OnResumeAsync() + { + if (Owner.IsInvalidNode()) + return; + + if (_scene != null) + await _scene.OnResumeAsync(); + + // 恢复处理 + Owner.SetProcess(true); + Owner.SetPhysicsProcess(true); + Owner.SetProcessInput(true); + + _isActive = true; + } + + /// + /// 异步处理场景退出逻辑。 + /// 在场景即将被替换或关闭时调用,执行清理工作。 + /// + /// 表示退出操作完成的ValueTask。 + public virtual async ValueTask OnExitAsync() + { + _isTransitioning = true; + + if (_scene != null) + await _scene.OnExitAsync(); + + _isActive = false; + } + + /// + /// 异步卸载场景资源。 + /// 在场景完全退出后调用,释放占用的内存和资源。 + /// + /// 表示卸载操作完成的ValueTask。 + public virtual async ValueTask OnUnloadAsync() + { + if (_scene != null) + await _scene.OnUnloadAsync(); + + // 释放节点 + Owner.QueueFreeX(); + + _isLoaded = false; + _isTransitioning = false; + } + + #endregion +} \ No newline at end of file diff --git a/GFramework.Godot/scene/SceneBehaviorFactory.cs b/GFramework.Godot/scene/SceneBehaviorFactory.cs new file mode 100644 index 0000000..bff228a --- /dev/null +++ b/GFramework.Godot/scene/SceneBehaviorFactory.cs @@ -0,0 +1,43 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GFramework.Game.Abstractions.scene; +using Godot; + +namespace GFramework.Godot.scene; + +/// +/// 场景行为工厂类,根据节点类型自动创建合适的场景行为实例。 +/// 使用模式匹配选择最适合的行为类型。 +/// +public static class SceneBehaviorFactory +{ + /// + /// 根据节点类型创建对应的场景行为实例。 + /// + /// 节点类型,必须继承自 Node。 + /// 场景节点的所有者实例。 + /// 场景的唯一标识键。 + /// 创建的场景行为实例。 + public static ISceneBehavior Create(T owner, string key) + where T : Node + { + return owner switch + { + Node2D node2D => new Node2DSceneBehavior(node2D, key), + Node3D node3D => new Node3DSceneBehavior(node3D, key), + Control control => new ControlSceneBehavior(control, key), + _ => new GenericSceneBehavior(owner, key) + }; + } +} \ No newline at end of file diff --git a/GFramework.Godot/setting/GodotAudioSettings.cs b/GFramework.Godot/setting/GodotAudioSettings.cs index 485ee8a..fc453d5 100644 --- a/GFramework.Godot/setting/GodotAudioSettings.cs +++ b/GFramework.Godot/setting/GodotAudioSettings.cs @@ -34,7 +34,16 @@ public class GodotAudioSettings(ISettingsModel model, AudioBusMap audioBusMap) model.GetData().Reset(); } + /// + /// 获取音频设置的数据对象。 + /// 该属性提供对音频设置数据的只读访问。 + /// public ISettingsData Data { get; } = model.GetData(); + + /// + /// 获取音频设置数据的类型。 + /// 该属性返回音频设置数据的具体类型信息。 + /// public Type DataType { get; } = typeof(AudioSettings); /// diff --git a/GFramework.Godot/setting/GodotGraphicsSettings.cs b/GFramework.Godot/setting/GodotGraphicsSettings.cs index 2e43023..f089290 100644 --- a/GFramework.Godot/setting/GodotGraphicsSettings.cs +++ b/GFramework.Godot/setting/GodotGraphicsSettings.cs @@ -51,6 +51,15 @@ public class GodotGraphicsSettings(ISettingsModel model) : IResetApplyAbleSettin model.GetData().Reset(); } + /// + /// 获取图形设置的数据对象。 + /// 该属性提供对图形设置数据的只读访问。 + /// public ISettingsData Data { get; } = model.GetData(); + + /// + /// 获取图形设置数据的类型。 + /// 该属性返回图形设置数据的具体类型信息。 + /// public Type DataType { get; } = typeof(GraphicsSettings); } \ No newline at end of file diff --git a/GFramework.Godot/setting/GodotLocalizationSettings.cs b/GFramework.Godot/setting/GodotLocalizationSettings.cs index 36665a7..16bc255 100644 --- a/GFramework.Godot/setting/GodotLocalizationSettings.cs +++ b/GFramework.Godot/setting/GodotLocalizationSettings.cs @@ -48,6 +48,15 @@ public class GodotLocalizationSettings(ISettingsModel model, LocalizationMap loc model.GetData().Reset(); } + /// + /// 获取本地化设置的数据对象。 + /// 该属性提供对本地化设置数据的只读访问。 + /// public ISettingsData Data { get; } = model.GetData(); + + /// + /// 获取本地化设置数据的类型。 + /// 该属性返回本地化设置数据的具体类型信息。 + /// public Type DataType { get; } = typeof(LocalizationSettings); } \ No newline at end of file diff --git a/GFramework.Godot/ui/GodotUiFactory.cs b/GFramework.Godot/ui/GodotUiFactory.cs index 5aeaf2a..4a7c231 100644 --- a/GFramework.Godot/ui/GodotUiFactory.cs +++ b/GFramework.Godot/ui/GodotUiFactory.cs @@ -16,7 +16,7 @@ public class GodotUiFactory : AbstractContextUtility, IUiFactory /// 日志记录器,用于记录调试信息。 /// private static readonly ILogger Log = - LoggerFactoryResolver.Provider.CreateLogger("GodotUiFactory"); + LoggerFactoryResolver.Provider.CreateLogger(nameof(GodotUiFactory)); /// /// UI注册表,用于管理UI场景资源。