GFramework/GFramework.Godot/ui/GodotUiRegistry.cs
GeWuYou d1b4ef1971 feat(godot): 添加Godot UI注册表和日志测试用例
- 实现GodotUiRegistry类用于管理PackedScene类型的UI资源注册和获取
- 添加完整的控制台日志记录器单元测试覆盖所有日志级别和功能
- 添加日志工厂相关测试用例验证不同配置下的日志行为
- 实现基础日志抽象类的完整测试覆盖各种日志记录场景
2026-01-15 20:51:06 +08:00

40 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.Game.Abstractions.ui;
using Godot;
namespace GFramework.Godot.ui;
/// <summary>
/// Godot UI注册表实现类用于管理PackedScene类型的UI资源注册和获取
/// </summary>
public class GodotUiRegistry : IWritableUiRegistry<PackedScene>
{
/// <summary>
/// 存储UI键值对的字典键为UI标识符值为对应的PackedScene对象
/// </summary>
private readonly Dictionary<string, PackedScene> _map = new(StringComparer.Ordinal);
/// <summary>
/// 注册UI场景到注册表中
/// </summary>
/// <param name="key">UI的唯一标识符</param>
/// <param name="scene">要注册的PackedScene对象</param>
/// <returns>返回当前UI注册表实例支持链式调用</returns>
public IWritableUiRegistry<PackedScene> Register(string key, PackedScene scene)
{
_map[key] = scene;
return this;
}
/// <summary>
/// 根据键获取已注册的UI场景
/// </summary>
/// <param name="uiKey">UI的唯一标识符</param>
/// <exception cref="KeyNotFoundException">当指定的键未找到对应的UI场景时抛出异常</exception>
/// <returns>对应的PackedScene对象</returns>
public PackedScene Get(string uiKey)
{
return !_map.TryGetValue(uiKey, out var scene)
? throw new KeyNotFoundException($"UI not registered: {uiKey}")
: scene;
}
}