using UnityEngine; using FairyGUI; using YooAsset; namespace GFGGame { public class GFGGLoader : GLoader { private AssetOperationHandle handle; protected override void LoadExternal() { //LogUtil.LogEditor($"GFGGLoader this.url {this.url}"); if (!YooAssets.CheckResExist(this.url)) { return; } bool isAsync = !this.url.Contains(ResPathUtil.TEXTURE_BGIMG_DIR_PATH); if (isAsync) { //异步 handle = YooAssets.LoadAssetAsync(this.url); handle.Completed += Handle_Completed; } else { //同步 handle = YooAssets.LoadAssetSync(this.url); Handle_Completed(handle); } } protected override void FreeExternal(NTexture texture) { //释放外部载入的资源 if(handle != null) { handle.Release(); handle = null; } } void Handle_Completed(AssetOperationHandle handle) { if(handle.GetAssetInfo().AssetPath != this.url) { handle.Release(); return; } Texture2D texture = handle.AssetObject as Texture2D; if (texture != null) { onExternalLoadSuccess(new NTexture(texture)); } else { onExternalLoadFailed(); } } } }