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 loadCbList = new List(); 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.singleton.ABManager != null; if (flag) { this.assetBundleInfo = XSingleton.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(this.asset) as GameObject; XResourceLoaderMgr.instanceCount++; XSingleton.singleton.AssetsRefRetain(this.hash); XSingleton.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.singleton.useNewMgr; if (useNewMgr) { XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo; bool uoiasync = XSingleton.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.singleton.GetUOI(uniteObjectInfo, this.isSharedRes, loadInfo.usePool); loadInfo.loadCb(uoi, this.cbObj); } i++; } this.loadCbList.Clear(); } } else { XSingleton.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.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.singleton.GetAssetInPool(this.hash); XSingleton.singleton.AssetsRefRetain(this.hash); loadCb(assetInPool, this.cbObj); } private void CreateFromPrefabCb(LoadCallBack loadCb, AssetBundleInfo info = null) { UnityEngine.Object assetInPool = XSingleton.singleton.GetAssetInPool(this.hash); GameObject gameObject = XCommon.Instantiate(assetInPool) as GameObject; XSingleton.singleton.AssetsRefRetain(this.hash); XSingleton.singleton.LogReverseID(gameObject, this.hash); loadCb(gameObject, this.cbObj); } } }