| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using UnityEngine;
- using FairyGUI;
- using YooAsset;
- namespace GFGGame
- {
- public class GFGGLoader : GLoader
- {
- private AssetHandle handle;
- //TODO webgl异步加载
- 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);
- //异步
- handle = YooAssets.LoadAssetAsync<Texture2D>(this.url);
- handle.Completed += Handle_Completed;
- // if (isAsync)
- // {
- // //异步
- // handle = YooAssets.LoadAssetAsync<Texture2D>(this.url);
- // handle.Completed += Handle_Completed;
- // }
- // else
- // {
- // //同步
- // handle = YooAssets.LoadAssetSync<Texture2D>(this.url);
- // Handle_Completed(handle);
- // }
- }
- protected override void FreeExternal(NTexture texture)
- {
- //释放外部载入的资源
- if(handle != null)
- {
- handle.Release();
- handle = null;
- }
- }
- void Handle_Completed(AssetHandle 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();
- }
- }
- }
- }
|