GFGGLoader.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. using FairyGUI;
  3. using YooAsset;
  4. namespace GFGGame
  5. {
  6. public class GFGGLoader : GLoader
  7. {
  8. private AssetOperationHandle handle;
  9. protected override void LoadExternal()
  10. {
  11. if (!YooAssets.CheckResExist(this.url))
  12. {
  13. return;
  14. }
  15. handle = YooAssets.LoadAssetAsync<Texture2D>(this.url);
  16. handle.Completed += Handle_Completed;
  17. }
  18. protected override void FreeExternal(NTexture texture)
  19. {
  20. //释放外部载入的资源
  21. if(handle != null)
  22. {
  23. handle.Release();
  24. }
  25. }
  26. void Handle_Completed(AssetOperationHandle handle)
  27. {
  28. if(handle.GetAssetInfo().AssetPath != this.url)
  29. {
  30. handle.Release();
  31. return;
  32. }
  33. Texture2D texture = handle.AssetObject as Texture2D;
  34. if (texture != null)
  35. {
  36. onExternalLoadSuccess(new NTexture(texture));
  37. }
  38. else
  39. {
  40. onExternalLoadFailed();
  41. }
  42. }
  43. }
  44. }