GFGGLoader.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. //异步
  16. handle = YooAssets.LoadAssetAsync<Texture2D>(this.url);
  17. handle.Completed += Handle_Completed;
  18. //同步
  19. //handle = YooAssets.LoadAssetSync<Texture2D>(this.url);
  20. //Handle_Completed(handle);
  21. }
  22. protected override void FreeExternal(NTexture texture)
  23. {
  24. //释放外部载入的资源
  25. if(handle != null)
  26. {
  27. handle.Release();
  28. handle = null;
  29. }
  30. }
  31. void Handle_Completed(AssetOperationHandle handle)
  32. {
  33. if(handle.GetAssetInfo().AssetPath != this.url)
  34. {
  35. handle.Release();
  36. return;
  37. }
  38. Texture2D texture = handle.AssetObject as Texture2D;
  39. if (texture != null)
  40. {
  41. onExternalLoadSuccess(new NTexture(texture));
  42. }
  43. else
  44. {
  45. onExternalLoadFailed();
  46. }
  47. }
  48. }
  49. }