AssetsBundleLoaderAsync.cs 916 B

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