using System.Threading; using Cysharp.Threading.Tasks; using TEngine; using UnityEngine; namespace GameLogic { /// /// UI资源加载器接口。 /// public interface IUIResourceLoader { /// /// 同步加载游戏物体并实例化。 /// /// 资源的定位地址。 /// 资源实例父节点。 /// 指定资源包的名称。不传使用默认资源包 /// 资源实例。 /// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。 public GameObject LoadGameObject(string location, Transform parent = null, string packageName = ""); /// /// 异步加载游戏物体并实例化。 /// /// 资源定位地址。 /// 资源实例父节点。 /// 取消操作Token。 /// 指定资源包的名称。不传使用默认资源包 /// 异步游戏物体实例。 /// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。 public UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default, string packageName = ""); } /// /// 默认UI资源加载器。 /// public class UIResourceLoader : IUIResourceLoader { private readonly IResourceModule _resourceLoaderImp = ModuleSystem.GetModule(); /// /// 同步加载游戏物体并实例化。 /// /// 资源的定位地址。 /// 资源实例父节点。 /// 指定资源包的名称。不传使用默认资源包 /// 资源实例。 /// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。 public GameObject LoadGameObject(string location, Transform parent = null, string packageName = "") { return _resourceLoaderImp.LoadGameObject(location, parent, packageName); } /// /// 异步加载游戏物体并实例化。 /// /// 资源定位地址。 /// 资源实例父节点。 /// 取消操作Token。 /// 指定资源包的名称。不传使用默认资源包 /// 异步游戏物体实例。 /// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。 public async UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default, string packageName = "") { return await _resourceLoaderImp.LoadGameObjectAsync(location, parent, cancellationToken, packageName); } } }