AssetsBundleLoaderAsync.cs 894 B

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