AssetBundleCreateRequestAsync.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using XGame.Framework.Asyncs;
  2. using UnityEngine;
  3. namespace XGame.Framework.Asset
  4. {
  5. internal class AssetBundleCreateRequestAsync : Async, IAssetAsync
  6. {
  7. private AssetBundleCreateRequest request;
  8. public string Path { get; internal set; }
  9. public uint Offset { get; internal set; }
  10. /// <summary>
  11. /// 此处先存bundleName
  12. /// </summary>
  13. public string AddressableName { get; internal set; }
  14. public override float Progress
  15. {
  16. get => request != null ? request.progress : 0;
  17. protected set => base.Progress = value;
  18. }
  19. public void Start()
  20. {
  21. //Log.Warn($"AssetBundleCreateRequestAsync Start. Path:{Path}");
  22. request = Offset > 0 ? AssetBundle.LoadFromFileAsync(Path, 0, Offset) : AssetBundle.LoadFromFileAsync(Path);
  23. request.completed += OnCompleted;
  24. }
  25. void OnCompleted(AsyncOperation async)
  26. {
  27. if (!async.isDone || request.assetBundle == null)
  28. AssetsLog.Warn("{0} is not a valid bundle. name:{1} instance:{2}", Path, AddressableName, request.assetBundle?.GetInstanceID());
  29. Completed();
  30. }
  31. public object GetResult()
  32. {
  33. object result = null;
  34. if (request != null)
  35. {
  36. //Log.Warn($"AssetBundleCreateRequestAsync Get bundle:{request.assetBundle? .GetInstanceID()??0} Path:{Path}");
  37. result = request.assetBundle;
  38. }
  39. Clear();
  40. return result;
  41. }
  42. void Clear()
  43. {
  44. request = null;
  45. }
  46. }
  47. }