| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System.IO;
- using System.Threading.Tasks;
- using UnityEngine;
- namespace Model
- {
- [ObjectSystem]
- public class AssetsLoaderAsyncAwakeSystem : AwakeSystem<AssetsLoaderAsync, AssetBundle>
- {
- public override void Awake(AssetsLoaderAsync self, AssetBundle a)
- {
- self.Awake(a);
- }
- }
- [ObjectSystem]
- public class AssetsLoaderAsyncUpdateSystem : UpdateSystem<AssetsLoaderAsync>
- {
- public override void Update(AssetsLoaderAsync self)
- {
- self.Update();
- }
- }
- public class AssetsLoaderAsync : Component
- {
- private AssetBundle assetBundle;
- private AssetBundleRequest request;
- private TaskCompletionSource<bool> tcs;
- public void Awake(AssetBundle ab)
- {
- this.assetBundle = ab;
- }
- public void Update()
- {
- if (!this.request.isDone)
- {
- return;
- }
- TaskCompletionSource<bool> t = tcs;
- t.SetResult(true);
- }
- public override void Dispose()
- {
- if (this.IsDisposed)
- {
- return;
- }
- base.Dispose();
- this.assetBundle = null;
- this.request = null;
- }
- public async Task<UnityEngine.Object[]> LoadAllAssetsAsync()
- {
- await InnerLoadAllAssetsAsync();
- return this.request.allAssets;
- }
- private Task<bool> InnerLoadAllAssetsAsync()
- {
- this.tcs = new TaskCompletionSource<bool>();
- this.request = assetBundle.LoadAllAssetsAsync();
- return this.tcs.Task;
- }
- }
- }
|