mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-24 04:06:48 +08:00
- 删除 AbstractAssetCatalogUtility 类及其所有实现逻辑 - 移除 AssetCatalog 相关结构体和接口定义 - 删除 IAssetCatalogUtility 和 IResourceFactoryUtility 接口 - 移除 AbstractResourceFactoryUtility 和 ResourceLoadUtility 实现 - 重命名 IUiRegistry 接口为 IAssetRegistry 并更新泛型参数说明 - 重命名 GodotUiRegistry 为 GodotAssetRegistry 并更新接口引用 - 创建新的 IGodotAssetRegistry 接口用于PackedScene资源管理 - 创建新的 IGodotSceneRegistry 接口并更新 GodotSceneRegistry 实现 - 更新 GodotUiFactory 中的依赖注入从 IUiRegistry 改为 IAssetRegistry
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using GFramework.Core.extensions;
|
||
using GFramework.Core.utility;
|
||
using GFramework.Game.Abstractions.ui;
|
||
using Godot;
|
||
|
||
namespace GFramework.Godot.ui;
|
||
|
||
/// <summary>
|
||
/// Godot UI工厂类,用于创建UI页面实例
|
||
/// 继承自AbstractContextUtility并实现IUiFactory接口
|
||
/// </summary>
|
||
public class GodotUiFactory : AbstractContextUtility, IUiFactory
|
||
{
|
||
/// <summary>
|
||
/// UI注册表,用于存储和获取PackedScene类型的UI资源
|
||
/// </summary>
|
||
private IAssetRegistry<PackedScene> _registry = null!;
|
||
|
||
/// <summary>
|
||
/// 根据指定的UI键创建UI页面实例
|
||
/// </summary>
|
||
/// <param name="uiKey">UI资源的唯一标识键</param>
|
||
/// <returns>实现IUiPage接口的UI页面实例</returns>
|
||
/// <exception cref="InvalidCastException">当UI场景没有继承IUiPage接口时抛出</exception>
|
||
public IUiPageBehavior Create(string uiKey)
|
||
{
|
||
// 从注册表中获取对应的场景资源
|
||
var scene = _registry.Get(uiKey);
|
||
|
||
// 实例化场景节点
|
||
var node = scene.Instantiate();
|
||
|
||
// 验证节点是否实现了IUiPageProvider接口
|
||
if (node is not IUiPageBehaviorProvider provider)
|
||
throw new InvalidCastException(
|
||
$"UI scene {uiKey} must implement IUiPageBehaviorProvider");
|
||
|
||
// 获取并返回页面行为实例
|
||
return provider.GetPage();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化方法,获取UI注册表实例
|
||
/// </summary>
|
||
protected override void OnInit()
|
||
{
|
||
_registry = this.GetUtility<IAssetRegistry<PackedScene>>()!;
|
||
}
|
||
} |