AssetsBundleLoaderAsync.cs 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.IO;
  2. using System.Threading.Tasks;
  3. using UnityEngine;
  4. namespace Model
  5. {
  6. [ObjectSystem]
  7. public class AssetsBundleLoaderAsyncSystem : ObjectSystem<AssetsBundleLoaderAsync>, IUpdate
  8. {
  9. public void Update()
  10. {
  11. this.Get().Update();
  12. }
  13. }
  14. public class AssetsBundleLoaderAsync : Disposer, IUpdate
  15. {
  16. private AssetBundleCreateRequest request;
  17. private TaskCompletionSource<AssetBundle> tcs;
  18. public void Update()
  19. {
  20. if (!this.request.isDone)
  21. {
  22. return;
  23. }
  24. TaskCompletionSource<AssetBundle> t = tcs;
  25. t.SetResult(this.request.assetBundle);
  26. }
  27. public override void Dispose()
  28. {
  29. if (this.Id == 0)
  30. {
  31. return;
  32. }
  33. base.Dispose();
  34. }
  35. public Task<AssetBundle> LoadAsync(string bundleName)
  36. {
  37. this.tcs = new TaskCompletionSource<AssetBundle>();
  38. this.request = AssetBundle.LoadFromFileAsync(Path.Combine(PathHelper.AppHotfixResPath, bundleName));
  39. return this.tcs.Task;
  40. }
  41. }
  42. }