summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs')
-rw-r--r--Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs238
1 files changed, 238 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs b/Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs
new file mode 100644
index 00000000..f728914b
--- /dev/null
+++ b/Client/Assets/Scripts/XUtliPoolLib/LoadAsyncTask.cs
@@ -0,0 +1,238 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+using XUpdater;
+
+namespace XUtliPoolLib
+{
+ public class LoadAsyncTask
+ {
+ public EAsyncLoadState loadState = EAsyncLoadState.EFree;
+
+ public Type loadType = null;
+
+ public uint hash = 0u;
+
+ public string location = "";
+
+ public string ext = "";
+
+ public bool isSharedRes = true;
+
+ public UnityEngine.Object asset = null;
+
+ public List<LoadInfo> loadCbList = new List<LoadInfo>();
+
+ private AssetBundleInfo assetBundleInfo = null;
+
+ public object cbObj = null;
+
+ public void Clear()
+ {
+ this.loadState = EAsyncLoadState.EFree;
+ this.location = "";
+ this.hash = 0u;
+ this.asset = null;
+ this.loadCbList.Clear();
+ this.loadType = null;
+ this.assetBundleInfo = null;
+ this.cbObj = null;
+ }
+
+ public bool Update()
+ {
+ bool result;
+ switch (this.loadState)
+ {
+ case EAsyncLoadState.EFree:
+ result = false;
+ break;
+ case EAsyncLoadState.EPreLoading:
+ {
+ bool flag = XSingleton<XUpdater.XUpdater>.singleton.ABManager != null;
+ if (flag)
+ {
+ this.assetBundleInfo = XSingleton<XUpdater.XUpdater>.singleton.ABManager.LoadImm(this.hash, this.location, this.ext, null);
+ }
+ bool flag2 = this.assetBundleInfo == null;
+ if (flag2)
+ {
+ this.asset = Resources.Load(this.location, this.loadType);
+ XResourceLoaderMgr.resourceLoadCount++;
+ }
+ else
+ {
+ int num = this.location.LastIndexOf("/");
+ bool flag3 = num > 0 && num + 1 < this.location.Length;
+ if (flag3)
+ {
+ string text = this.location.Substring(num + 1);
+ }
+ else
+ {
+ string text = this.location;
+ }
+ this.asset = this.assetBundleInfo.mainObject;
+ XResourceLoaderMgr.abLoadCount++;
+ }
+ this.loadState = EAsyncLoadState.ELoading;
+ result = false;
+ break;
+ }
+ case EAsyncLoadState.ELoading:
+ this.LoadComplete();
+ this.loadState = EAsyncLoadState.EFree;
+ result = true;
+ break;
+ case EAsyncLoadState.EInstance:
+ {
+ bool flag4 = this.asset != null;
+ if (flag4)
+ {
+ int i = 0;
+ int count = this.loadCbList.Count;
+ while (i < count)
+ {
+ LoadInfo loadInfo = this.loadCbList[i];
+ bool flag5 = loadInfo.loadCb != null;
+ if (flag5)
+ {
+ GameObject gameObject = XCommon.Instantiate<UnityEngine.Object>(this.asset) as GameObject;
+ XResourceLoaderMgr.instanceCount++;
+ XSingleton<XResourceLoaderMgr>.singleton.AssetsRefRetain(this.hash);
+ XSingleton<XResourceLoaderMgr>.singleton.LogReverseID(gameObject, this.hash);
+ loadInfo.loadCb(gameObject, this.cbObj);
+ }
+ i++;
+ }
+ this.loadCbList.Clear();
+ }
+ result = true;
+ break;
+ }
+ default:
+ result = false;
+ break;
+ }
+ return result;
+ }
+
+ public void CancelLoad(LoadCallBack cb)
+ {
+ int count = this.loadCbList.Count;
+ for (int i = count - 1; i >= 0; i--)
+ {
+ LoadInfo loadInfo = this.loadCbList[i];
+ bool flag = loadInfo.loadCb == cb;
+ if (flag)
+ {
+ this.loadCbList.RemoveAt(i);
+ }
+ }
+ }
+
+ private void ReturnNull()
+ {
+ int i = 0;
+ int count = this.loadCbList.Count;
+ while (i < count)
+ {
+ LoadInfo loadInfo = this.loadCbList[i];
+ bool flag = loadInfo.loadCb != null;
+ if (flag)
+ {
+ loadInfo.loadCb(null, this.cbObj);
+ }
+ i++;
+ }
+ this.loadCbList.Clear();
+ }
+
+ private void LoadComplete()
+ {
+ bool flag = this.asset == null;
+ if (flag)
+ {
+ XResourceLoaderMgr.LoadErrorLog(this.location);
+ this.ReturnNull();
+ }
+ else
+ {
+ bool useNewMgr = XSingleton<XResourceLoaderMgr>.singleton.useNewMgr;
+ if (useNewMgr)
+ {
+ XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo;
+ bool uoiasync = XSingleton<XResourceLoaderMgr>.singleton.GetUOIAsync(this.location, this.hash, null, this.assetBundleInfo, this.isSharedRes, out uniteObjectInfo);
+ bool flag2 = uniteObjectInfo != null;
+ if (flag2)
+ {
+ int i = 0;
+ int count = this.loadCbList.Count;
+ while (i < count)
+ {
+ LoadInfo loadInfo = this.loadCbList[i];
+ bool flag3 = loadInfo.loadCb != null;
+ if (flag3)
+ {
+ UnityEngine.Object uoi = XSingleton<XResourceLoaderMgr>.singleton.GetUOI(uniteObjectInfo, this.isSharedRes, loadInfo.usePool);
+ loadInfo.loadCb(uoi, this.cbObj);
+ }
+ i++;
+ }
+ this.loadCbList.Clear();
+ }
+ }
+ else
+ {
+ XSingleton<XResourceLoaderMgr>.singleton.AddAssetInPool(this.asset, this.hash, this.assetBundleInfo);
+ int j = 0;
+ int count2 = this.loadCbList.Count;
+ while (j < count2)
+ {
+ LoadInfo loadInfo2 = this.loadCbList[j];
+ bool flag4 = loadInfo2.loadCb != null;
+ if (flag4)
+ {
+ bool flag5 = this.isSharedRes;
+ if (flag5)
+ {
+ this.GetSharedResourceCb(loadInfo2.loadCb, this.assetBundleInfo);
+ }
+ else
+ {
+ UnityEngine.Object obj = null;
+ bool flag6 = loadInfo2.usePool && XSingleton<XResourceLoaderMgr>.singleton.GetInObjectPool(ref obj, this.hash);
+ if (flag6)
+ {
+ loadInfo2.loadCb(obj, this.cbObj);
+ }
+ else
+ {
+ this.CreateFromPrefabCb(loadInfo2.loadCb, this.assetBundleInfo);
+ }
+ }
+ }
+ j++;
+ }
+ this.loadCbList.Clear();
+ }
+ }
+ }
+
+ private void GetSharedResourceCb(LoadCallBack loadCb, AssetBundleInfo info = null)
+ {
+ UnityEngine.Object assetInPool = XSingleton<XResourceLoaderMgr>.singleton.GetAssetInPool(this.hash);
+ XSingleton<XResourceLoaderMgr>.singleton.AssetsRefRetain(this.hash);
+ loadCb(assetInPool, this.cbObj);
+ }
+
+ private void CreateFromPrefabCb(LoadCallBack loadCb, AssetBundleInfo info = null)
+ {
+ UnityEngine.Object assetInPool = XSingleton<XResourceLoaderMgr>.singleton.GetAssetInPool(this.hash);
+ GameObject gameObject = XCommon.Instantiate<UnityEngine.Object>(assetInPool) as GameObject;
+ XSingleton<XResourceLoaderMgr>.singleton.AssetsRefRetain(this.hash);
+ XSingleton<XResourceLoaderMgr>.singleton.LogReverseID(gameObject, this.hash);
+ loadCb(gameObject, this.cbObj);
+ }
+ }
+}