AssetsBundleLoaderAsync.cs 894 字节
Newer Older
T
tanghai 已提交
1 2 3 4
using System.IO;
using System.Threading.Tasks;
using UnityEngine;

5
namespace ET
T
tanghai 已提交
6
{
T
tanghai 已提交
7
	
8
	public class AssetsBundleLoaderAsyncSystem : UpdateSystem<AssetsBundleLoaderAsync>
T
tanghai 已提交
9
	{
10
		public override void Update(AssetsBundleLoaderAsync self)
T
tanghai 已提交
11
		{
12
			self.Update();
T
tanghai 已提交
13 14 15
		}
	}

T
tanghai 已提交
16
	public class AssetsBundleLoaderAsync : Entity
T
tanghai 已提交
17 18 19
	{
		private AssetBundleCreateRequest request;

20
		private ETTaskCompletionSource<AssetBundle> tcs;
T
tanghai 已提交
21 22 23 24 25 26 27 28

		public void Update()
		{
			if (!this.request.isDone)
			{
				return;
			}

29
			ETTaskCompletionSource<AssetBundle> t = tcs;
T
tanghai 已提交
30 31 32 33 34
			t.SetResult(this.request.assetBundle);
		}

		public override void Dispose()
		{
T
tanghai 已提交
35
			if (this.IsDisposed)
T
tanghai 已提交
36 37 38 39 40 41
			{
				return;
			}
			base.Dispose();
		}

42
		public ETTask<AssetBundle> LoadAsync(string path)
T
tanghai 已提交
43
		{
44
			this.tcs = new ETTaskCompletionSource<AssetBundle>();
45
			this.request = AssetBundle.LoadFromFileAsync(path);
T
tanghai 已提交
46 47 48 49
			return this.tcs.Task;
		}
	}
}