GFGGLoader.cs 1.5 KB

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