From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XUtliPoolLib/XResourceLoaderMgr.cs | 2151 ++++++++++++++++++++ 1 file changed, 2151 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/XResourceLoaderMgr.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/XResourceLoaderMgr.cs') diff --git a/Client/Assets/Scripts/XUtliPoolLib/XResourceLoaderMgr.cs b/Client/Assets/Scripts/XUtliPoolLib/XResourceLoaderMgr.cs new file mode 100644 index 00000000..60573975 --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/XResourceLoaderMgr.cs @@ -0,0 +1,2151 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; +using UnityEngine; +using XUpdater; + +namespace XUtliPoolLib +{ + public sealed class XResourceLoaderMgr : XSingleton + { + public static uint Preload = 1u; + + public static uint SharedResource = 2u; + + public static uint DontDestroyAsset = 4u; + + public static uint Degeneration = 8u; + + public static readonly Vector3 Far_Far_Away = new Vector3(0f, -1000f, 0f); + + public bool useNewMgr = false; + + public bool dontDestroy = false; + + private Dictionary _bundle_pool = new Dictionary(); + + private Dictionary _asset_ref_count = new Dictionary(); + + private Dictionary> _object_pool = new Dictionary>(); + + private Dictionary _asset_pool = new Dictionary(); + + private Dictionary _script_pool = new Dictionary(); + + private Dictionary _reverse_map = new Dictionary(); + + private Dictionary m_assetPool = new Dictionary(); + + private Dictionary m_instanceIDAssetMap = new Dictionary(); + + private Queue m_objInfoPool = new Queue(); + + private XResourceLoaderMgr.UniteObjectInfo m_degenerationQueue = null; + + private XResourceLoaderMgr.UniteObjectInfo m_currentDegeneration = null; + + private List m_curveData = null; + + public static bool UseCurveTable = false; + + private BeforeUnityUnLoadResource m_BeforeUnityUnLoadResourceCb = null; + + private XmlSerializer[] xmlSerializerCache = new XmlSerializer[2]; + + private MemoryStream shareMemoryStream = new MemoryStream(8192); + + private List _async_task_list = new List(); + + private List delayUpdateList = new List(); + + public static double delayTime = 0.5; + + private double currentDelayTime = -1.0; + + public bool DelayLoad = false; + + public bool isCurrentLoading = false; + + public float maxLoadThresholdTime = 0.1f; + + public static int resourceLoadCount = 0; + + public static int abLoadCount = 0; + + public static int instanceCount = 0; + + private uint _prefixHash = 0u; + + public class UniteObjectInfo + { + public bool HasPreload + { + get + { + return (this.m_flag & XResourceLoaderMgr.Preload) > 0u; + } + set + { + if (value) + { + this.m_flag |= XResourceLoaderMgr.Preload; + } + else + { + this.m_flag &= ~XResourceLoaderMgr.Preload; + } + } + } + + public bool IsSharedResource + { + get + { + return (this.m_flag & XResourceLoaderMgr.SharedResource) > 0u; + } + set + { + if (value) + { + this.m_flag |= XResourceLoaderMgr.SharedResource; + } + else + { + this.m_flag &= ~XResourceLoaderMgr.SharedResource; + } + } + } + + public bool IsDontDestroyAsset + { + get + { + return (this.m_flag & XResourceLoaderMgr.DontDestroyAsset) > 0u; + } + set + { + if (value) + { + this.m_flag |= XResourceLoaderMgr.DontDestroyAsset; + } + else + { + this.m_flag &= ~XResourceLoaderMgr.DontDestroyAsset; + } + } + } + + public bool IsDegeneration + { + get + { + return (this.m_flag & XResourceLoaderMgr.Degeneration) > 0u; + } + set + { + if (value) + { + this.m_flag |= XResourceLoaderMgr.Degeneration; + } + else + { + this.m_flag &= ~XResourceLoaderMgr.Degeneration; + } + } + } + + public uint hashID = 0u; + + public UnityEngine.Object asset = null; + + public int refCount = 0; + + public AssetBundleInfo assetBundleInfo = null; + + public Queue objPool = null; + + public string loc = ""; + + private uint m_flag = 0u; + + public XResourceLoaderMgr.UniteObjectInfo next = null; + + public float degenerationTime = 0f; + + private void InitAB(string location, string suffix) + { + bool flag = XSingleton.singleton.ABManager != null; + if (flag) + { + this.assetBundleInfo = XSingleton.singleton.ABManager.LoadImm(this.hashID, location, suffix, null); + } + } + + public bool Init(string location, string suffix, uint hash, bool isSharedResource, Type t, bool canNotNull) + { + this.loc = location; + this.IsSharedResource = isSharedResource; + this.hashID = hash; + this.InitAB(location, suffix); + bool flag = this.assetBundleInfo != null; + if (flag) + { + this.asset = this.assetBundleInfo.mainObject; + } + else + { + this.asset = Resources.Load(location, t); + } + bool flag2 = this.asset == null && canNotNull; + bool result; + if (flag2) + { + XResourceLoaderMgr.LoadErrorLog(location); + result = false; + } + else + { + result = canNotNull; + } + return result; + } + + public bool InitAnim(string location, string suffix, uint hash) + { + this.loc = location; + this.IsSharedResource = true; + this.hashID = hash; + this.InitAB(location, suffix); + float length = 0f; + bool flag = this.assetBundleInfo != null; + AnimationClip animationClip; + if (flag) + { + animationClip = (this.assetBundleInfo.mainObject as AnimationClip); + bool flag2 = animationClip != null; + if (flag2) + { + length = animationClip.length; + } + } + else + { + animationClip = Resources.Load(location); + bool flag3 = animationClip != null; + if (flag3) + { + length = animationClip.length; + } + } + bool flag4 = animationClip == null; + bool result; + if (flag4) + { + XResourceLoaderMgr.LoadErrorLog(location); + result = false; + } + else + { + XAnimationClip xanimationClip = XAnimationPool.Get(); + xanimationClip.clip = animationClip; + xanimationClip.length = length; + this.asset = xanimationClip; + result = true; + } + return result; + } + + public bool InitAsync(string location, uint hash, UnityEngine.Object asyncAsset, AssetBundleInfo info, bool isSharedResource, bool showLog) + { + this.loc = location; + this.IsSharedResource = isSharedResource; + this.hashID = hash; + this.assetBundleInfo = info; + bool flag = this.assetBundleInfo != null; + if (flag) + { + this.asset = this.assetBundleInfo.mainObject; + } + else + { + this.asset = asyncAsset; + } + bool flag2 = this.asset is AnimationClip; + if (flag2) + { + float length = 0f; + bool flag3 = this.assetBundleInfo != null; + AnimationClip animationClip; + if (flag3) + { + animationClip = (this.assetBundleInfo.mainObject as AnimationClip); + bool flag4 = animationClip != null; + if (flag4) + { + length = animationClip.length; + } + } + else + { + animationClip = (asyncAsset as AnimationClip); + bool flag5 = animationClip != null; + if (flag5) + { + length = animationClip.length; + } + } + bool flag6 = animationClip != null; + if (flag6) + { + XAnimationClip xanimationClip = XAnimationPool.Get(); + xanimationClip.clip = animationClip; + xanimationClip.length = length; + this.asset = xanimationClip; + } + } + bool flag7 = this.asset == null && showLog; + bool result; + if (flag7) + { + XResourceLoaderMgr.LoadErrorLog(location); + result = false; + } + else + { + result = true; + } + return result; + } + + public UnityEngine.Object Get(bool useObjPool, bool preload = false) + { + UnityEngine.Object @object = null; + this.IsDegeneration = false; + if (preload) + { + this.HasPreload = true; + } + bool isSharedResource = this.IsSharedResource; + if (isSharedResource) + { + @object = this.asset; + } + else + { + bool flag = useObjPool && this.objPool != null && this.objPool.Count > 0; + if (flag) + { + @object = this.objPool.Dequeue(); + } + else + { + bool flag2 = this.asset != null; + if (flag2) + { + @object = XCommon.Instantiate(this.asset); + } + else + { + XSingleton.singleton.AddErrorLog("null asset when instantiate asset", null, null, null, null, null); + } + } + } + bool flag3 = @object != null; + if (flag3) + { + this.refCount++; + bool flag4 = this.assetBundleInfo != null && this.refCount == 1; + if (flag4) + { + this.assetBundleInfo.Retain(); + } + } + return @object; + } + + public bool Return(UnityEngine.Object obj, bool useObjPool) + { + this.refCount--; + bool flag = this.asset != null && this.refCount <= 0; + bool result; + if (flag) + { + bool flag2 = !this.IsSharedResource; + if (flag2) + { + bool flag3 = this.objPool == null; + if (flag3) + { + this.objPool = QueuePool.Get(); + } + this.objPool.Enqueue(obj); + } + this.IsDegeneration = true; + this.degenerationTime = 0f; + result = true; + } + else + { + bool flag4 = !this.IsSharedResource && obj != null; + if (flag4) + { + if (useObjPool) + { + bool flag5 = obj is GameObject; + if (flag5) + { + GameObject gameObject = obj as GameObject; + gameObject.transform.position = XResourceLoaderMgr.Far_Far_Away; + gameObject.transform.rotation = Quaternion.identity; + gameObject.transform.parent = null; + } + bool flag6 = this.objPool == null; + if (flag6) + { + this.objPool = QueuePool.Get(); + } + this.objPool.Enqueue(obj); + } + else + { + bool flag7 = XResourceLoaderMgr.UniteObjectInfo.CanDestroy(obj); + if (flag7) + { + UnityEngine.Object.Destroy(obj); + } + } + } + result = false; + } + return result; + } + + public void Clear() + { + bool flag = this.objPool != null; + if (flag) + { + while (this.objPool.Count > 0) + { + UnityEngine.Object @object = this.objPool.Dequeue(); + UnityEngine.Object.Destroy(@object); + } + QueuePool.Release(this.objPool); + this.objPool = null; + } + bool flag2 = this.assetBundleInfo != null; + if (flag2) + { + this.assetBundleInfo.Release(); + } + else + { + bool flag3 = !XResourceLoaderMgr.UniteObjectInfo.CanDestroy(this.asset); + if (flag3) + { + Resources.UnloadAsset(this.asset); + } + else + { + bool flag4 = this.asset is XAnimationClip; + if (flag4) + { + XAnimationClip xanimationClip = this.asset as XAnimationClip; + bool flag5 = xanimationClip.clip != null; + if (flag5) + { + Resources.UnloadAsset(xanimationClip.clip); + } + XAnimationPool.Release(xanimationClip); + } + } + } + this.loc = ""; + this.hashID = 0u; + this.asset = null; + this.refCount = 0; + this.next = null; + this.degenerationTime = 0f; + this.IsDegeneration = false; + this.assetBundleInfo = null; + } + + public void ClearPool() + { + bool flag = this.objPool != null; + if (flag) + { + while (this.objPool.Count > 0) + { + UnityEngine.Object @object = this.objPool.Dequeue(); + UnityEngine.Object.Destroy(@object); + } + QueuePool.Release(this.objPool); + this.objPool = null; + } + } + + public static bool CanDestroy(UnityEngine.Object obj) + { + return obj is GameObject || obj is ScriptableObject || obj is Material; + } + } + + public XResourceLoaderMgr() + { + this.xmlSerializerCache[0] = new XmlSerializer(typeof(XSkillData)); + this.xmlSerializerCache[1] = new XmlSerializer(typeof(XCutSceneData)); + this._prefixHash = XSingleton.singleton.XHashLowerRelpaceDot(this._prefixHash, "Assets.Resources."); + } + + public void LoadServerCurve(string location) + { + TextAsset sharedResource = this.GetSharedResource(location, ".bytes", true, false); + bool flag = sharedResource == null || sharedResource.bytes == null; + if (flag) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + XBinaryReader xbinaryReader = XBinaryReader.Get(); + xbinaryReader.Init(sharedResource); + int num = xbinaryReader.ReadInt32(); + XSingleton.singleton.AddLog("loadServerCurve" + num, null, null, null, null, null, XDebugColor.XDebug_None); + this.m_curveData = new List(num); + for (int i = 0; i < num; i++) + { + FloatCurve floatCurve = new FloatCurve(); + floatCurve.namehash = xbinaryReader.ReadUInt32(); + floatCurve.maxValue = xbinaryReader.ReadInt16(); + floatCurve.landValue = xbinaryReader.ReadInt16(); + int num2 = xbinaryReader.ReadInt32(); + bool flag2 = num2 > 0; + if (flag2) + { + floatCurve.value = new short[num2]; + for (int j = 0; j < num2; j++) + { + floatCurve.value[j] = xbinaryReader.ReadInt16(); + } + } + this.m_curveData.Add(floatCurve); + } + XBinaryReader.Return(xbinaryReader, false); + this.UnSafeDestroyShareResource(location, ".bytes", sharedResource, false); + } + + public void ReleasePool() + { + bool flag = this.useNewMgr; + if (flag) + { + foreach (KeyValuePair keyValuePair in this.m_assetPool) + { + XResourceLoaderMgr.UniteObjectInfo value = keyValuePair.Value; + bool flag2 = value.asset != null; + if (flag2) + { + bool flag3 = !value.IsDontDestroyAsset && !value.IsDegeneration; + if (flag3) + { + keyValuePair.Value.ClearPool(); + bool flag4 = value.HasPreload && value.refCount == 0; + if (flag4) + { + value.IsDegeneration = true; + value.degenerationTime = 2f; + bool flag5 = this.m_degenerationQueue == null; + if (flag5) + { + this.m_degenerationQueue = value; + this.m_currentDegeneration = value; + } + else + { + bool flag6 = this.m_currentDegeneration != null; + if (flag6) + { + this.m_currentDegeneration.next = value; + this.m_currentDegeneration = value; + } + } + bool flag7 = value.asset != null; + if (flag7) + { + this.m_instanceIDAssetMap.Remove(value.asset.GetInstanceID()); + } + } + else + { + XSingleton.singleton.AddWarningLog2("Asset Not Release:{0} Ref:{1}", new object[] + { + value.loc, + value.refCount + }); + } + } + } + else + { + XSingleton.singleton.AddWarningLog2("Asset null:{0} Ref:{1}", new object[] + { + value.loc, + value.refCount + }); + } + } + this.DelayDestroy(0f, true); + } + else + { + foreach (KeyValuePair> keyValuePair2 in this._object_pool) + { + while (keyValuePair2.Value.Count > 0) + { + this.UnSafeDestroy(keyValuePair2.Value.Dequeue(), false, true); + } + } + this._object_pool.Clear(); + this._asset_pool.Clear(); + this._script_pool.Clear(); + List list = new List(this._asset_ref_count.Keys); + for (int i = 0; i < list.Count; i++) + { + this._asset_ref_count[list[i]] = 0; + } + foreach (KeyValuePair keyValuePair3 in this._bundle_pool) + { + keyValuePair3.Value.Release(); + } + this._bundle_pool.Clear(); + } + XSingleton.singleton.AddWarningLog2("ResourceLoad:{0} ABLoad:{1} Instance:{2}", new object[] + { + XResourceLoaderMgr.resourceLoadCount, + XResourceLoaderMgr.abLoadCount, + XResourceLoaderMgr.instanceCount + }); + XResourceLoaderMgr.resourceLoadCount = 0; + XResourceLoaderMgr.abLoadCount = 0; + XResourceLoaderMgr.instanceCount = 0; + this.isCurrentLoading = false; + for (int j = 0; j < this._async_task_list.Count; j++) + { + this._async_task_list[j].Clear(); + } + this._async_task_list.Clear(); + this.shareMemoryStream.Close(); + this.shareMemoryStream = new MemoryStream(8192); + XSingleton.singleton.Clear(); + this.delayUpdateList.Clear(); + } + + public void DebugPrint() + { + foreach (KeyValuePair keyValuePair in this.m_assetPool) + { + XResourceLoaderMgr.UniteObjectInfo value = keyValuePair.Value; + bool flag = value.asset != null; + if (flag) + { + bool flag2 = !value.IsDontDestroyAsset; + if (flag2) + { + XSingleton.singleton.AddWarningLog2("Asset Not Release:{0} Ref:{1}", new object[] + { + value.loc, + value.refCount + }); + } + } + else + { + XSingleton.singleton.AddWarningLog2("Asset null:{0} Ref:{1}", new object[] + { + value.loc, + value.refCount + }); + } + } + } + + public void SetUnloadCallback(BeforeUnityUnLoadResource cb) + { + this.m_BeforeUnityUnLoadResourceCb = cb; + } + + public void CallUnloadCallback() + { + bool flag = this.m_BeforeUnityUnLoadResourceCb != null; + if (flag) + { + this.m_BeforeUnityUnLoadResourceCb(); + } + } + + private uint Hash(string location, string ext) + { + uint hash = XSingleton.singleton.XHashLowerRelpaceDot(this._prefixHash, location); + return XSingleton.singleton.XHashLowerRelpaceDot(hash, ext); + } + + public Stream ReadText(string location, string suffix, bool error = true) + { + TextAsset sharedResource = this.GetSharedResource(location, suffix, error, false); + bool flag = sharedResource == null; + if (flag) + { + if (!error) + { + return null; + } + XResourceLoaderMgr.LoadErrorLog(location); + } + Stream result; + try + { + this.shareMemoryStream.SetLength(0L); + this.shareMemoryStream.Write(sharedResource.bytes, 0, sharedResource.bytes.Length); + this.shareMemoryStream.Seek(0L, SeekOrigin.Begin); + result = this.shareMemoryStream; + } + catch (Exception ex) + { + XSingleton.singleton.AddErrorLog(ex.Message, location, null, null, null, null); + result = this.shareMemoryStream; + } + finally + { + this.UnSafeDestroyShareResource(location, suffix, sharedResource, false); + } + return result; + } + + public void ClearStream(Stream s) + { + bool flag = s != null; + if (flag) + { + bool flag2 = s == this.shareMemoryStream; + if (flag2) + { + this.shareMemoryStream.SetLength(0L); + } + else + { + s.Close(); + } + } + } + + public XBinaryReader ReadBinary(string location, string suffix, bool readShareResource, bool error = true) + { + TextAsset sharedResource = this.GetSharedResource(location, suffix, error, false); + bool flag = sharedResource == null; + if (flag) + { + if (!error) + { + return null; + } + XResourceLoaderMgr.LoadErrorLog(location); + } + XBinaryReader result; + try + { + XBinaryReader xbinaryReader = XBinaryReader.Get(); + xbinaryReader.Init(sharedResource); + this.UnSafeDestroyShareResource(location, suffix, sharedResource, false); + result = xbinaryReader; + } + catch (Exception ex) + { + XSingleton.singleton.AddErrorLog(ex.Message, location, null, null, null, null); + result = null; + } + return result; + } + + public void ClearBinary(XBinaryReader reader, bool readShareResource) + { + bool flag = reader != null; + if (flag) + { + XBinaryReader.Return(reader, readShareResource); + } + } + + public bool ReadText(string location, string suffix, XBinaryReader stream, bool error = true) + { + bool flag = true; + TextAsset sharedResource = this.GetSharedResource(location, suffix, error, false); + bool flag2 = sharedResource == null; + bool result; + if (flag2) + { + if (error) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + result = false; + } + else + { + stream.Init(sharedResource); + this.UnSafeDestroyShareResource(location, suffix, sharedResource, false); + result = flag; + } + return result; + } + + public TextAsset ReadLuaBytes(string filename_without_ext) + { + string location = "lua/Hotfix/" + filename_without_ext; + TextAsset sharedResource = this.GetSharedResource(location, ".txt", false, false); + bool flag = sharedResource == null; + TextAsset result; + if (flag) + { + result = null; + } + else + { + result = sharedResource; + } + return result; + } + + public void ReleaseLuaBytes(string filename_without_ext, TextAsset data) + { + string location = "lua/Hotfix/" + filename_without_ext; + this.UnSafeDestroyShareResource(location, ".txt", data, false); + } + + public bool ReadFile(string location, CVSReader reader) + { + TextAsset textAsset = null; + textAsset = this.GetSharedResource(location, ".bytes", true, false); + bool flag = textAsset == null || textAsset.bytes == null; + if (flag) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + bool flag2 = true; + XBinaryReader xbinaryReader = XBinaryReader.Get(); + xbinaryReader.Init(textAsset); + try + { + flag2 = reader.ReadFile(xbinaryReader); + bool flag3 = !flag2; + if (flag3) + { + XSingleton.singleton.AddErrorLog("in File: ", location, reader.error, null, null, null); + } + } + catch (Exception ex) + { + XSingleton.singleton.AddErrorLog(ex.Message, " in File: ", location, reader.error, null, null); + flag2 = false; + } + finally + { + XBinaryReader.Return(xbinaryReader, false); + } + this.UnSafeDestroyShareResource(location, ".bytes", textAsset, false); + return flag2; + } + + public bool ReadFile(TextAsset data, CVSReader reader) + { + bool flag = data == null || reader == null; + bool result; + if (flag) + { + result = false; + } + else + { + XBinaryReader xbinaryReader = XBinaryReader.Get(); + xbinaryReader.Init(data); + bool flag2 = true; + try + { + flag2 = reader.ReadFile(xbinaryReader); + return flag2; + } + catch (Exception ex) + { + XSingleton.singleton.AddErrorLog("ReadFile: ", ex.Message, null, null, null, null); + flag2 = false; + } + finally + { + XBinaryReader.Return(xbinaryReader, false); + } + result = flag2; + } + return result; + } + + public void CreateInAdvance(string location, int num, ECreateHideType hideType) + { + bool flag = location == null || location.Length == 0; + if (!flag) + { + uint num2 = this.Hash(location, ".prefab"); + int num3 = 0; + bool flag2 = this.useNewMgr; + if (flag2) + { + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = null; + bool flag3 = this.m_assetPool.TryGetValue(num2, out uniteObjectInfo); + if (flag3) + { + bool flag4 = uniteObjectInfo.objPool != null; + if (flag4) + { + num3 = uniteObjectInfo.objPool.Count; + } + } + else + { + uniteObjectInfo = this.GetObjectInfo(); + uniteObjectInfo.Init(location, ".prefab", num2, false, typeof(GameObject), true); + this.m_assetPool.Add(num2, uniteObjectInfo); + } + bool flag5 = uniteObjectInfo.objPool == null; + if (flag5) + { + uniteObjectInfo.objPool = QueuePool.Get(); + } + for (int i = 0; i < num - num3; i++) + { + bool flag6 = uniteObjectInfo.asset != null; + if (flag6) + { + GameObject gameObject = XCommon.Instantiate(uniteObjectInfo.asset) as GameObject; + bool flag7 = gameObject != null; + if (flag7) + { + uniteObjectInfo.objPool.Enqueue(gameObject); + switch (hideType) + { + case ECreateHideType.DisableObject: + gameObject.SetActive(false); + break; + case ECreateHideType.DisableAnim: + { + Animator componentInChildren = gameObject.GetComponentInChildren(); + bool flag8 = componentInChildren != null; + if (flag8) + { + componentInChildren.enabled = false; + } + break; + } + case ECreateHideType.DisableParticleRenderer: + XSingleton.singleton.EnableParticleRenderer(gameObject, false); + break; + } + } + } + } + } + else + { + bool flag9 = this._object_pool.ContainsKey(num2); + if (flag9) + { + Queue queue = this._object_pool[num2]; + num3 = queue.Count; + } + for (int j = 0; j < num - num3; j++) + { + UnityEngine.Object @object = this.CreateFromPrefab(location, false, false); + this.AddToObjectPool(num2, @object); + GameObject gameObject2 = @object as GameObject; + bool flag10 = gameObject2 != null; + if (flag10) + { + switch (hideType) + { + case ECreateHideType.DisableObject: + gameObject2.SetActive(false); + break; + case ECreateHideType.DisableAnim: + { + Animator componentInChildren2 = gameObject2.GetComponentInChildren(); + bool flag11 = componentInChildren2 != null; + if (flag11) + { + componentInChildren2.enabled = false; + } + break; + } + case ECreateHideType.DisableParticleRenderer: + XSingleton.singleton.EnableParticleRenderer(gameObject2, false); + break; + } + } + } + } + } + } + + public XResourceLoaderMgr.UniteObjectInfo GetUOI(uint hash, out UnityEngine.Object obj, bool useObjPool) + { + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = null; + obj = null; + bool flag = this.m_assetPool.TryGetValue(hash, out uniteObjectInfo); + XResourceLoaderMgr.UniteObjectInfo result; + if (flag) + { + obj = uniteObjectInfo.Get(useObjPool, false); + result = uniteObjectInfo; + } + else + { + result = null; + } + return result; + } + + public bool GetUOIAsync(string location, uint hash, UnityEngine.Object asset, AssetBundleInfo info, bool isSharedResource, out XResourceLoaderMgr.UniteObjectInfo uoi) + { + uoi = null; + bool flag = this.m_assetPool.TryGetValue(hash, out uoi); + bool result; + if (flag) + { + XSingleton.singleton.AddWarningLog2("LoadAsync asset:{0},already loaded.", new object[] + { + location + }); + bool flag2 = asset != uoi.asset; + if (flag2) + { + XSingleton.singleton.AddErrorLog("not same asset at same path.", null, null, null, null, null); + } + result = false; + } + else + { + uoi = this.GetObjectInfo(); + bool flag3 = uoi.InitAsync(location, hash, asset, info, isSharedResource, true); + bool flag4 = isSharedResource && uoi.asset != null; + if (flag4) + { + int instanceID = uoi.asset.GetInstanceID(); + bool flag5 = this.m_instanceIDAssetMap.ContainsKey(instanceID); + if (flag5) + { + XSingleton.singleton.AddErrorLog2("same key already exists in the dictionary:{0}", new object[] + { + uoi.asset.name + }); + } + else + { + this.m_instanceIDAssetMap[instanceID] = uoi; + } + } + this.m_assetPool.Add(hash, uoi); + result = flag3; + } + return result; + } + + public UnityEngine.Object GetUOI(XResourceLoaderMgr.UniteObjectInfo uoi, bool isSharedResource, bool useObjPool) + { + UnityEngine.Object @object = uoi.Get(useObjPool, false); + bool flag = !isSharedResource; + if (flag) + { + int instanceID = @object.GetInstanceID(); + bool flag2 = this.m_instanceIDAssetMap.ContainsKey(instanceID); + if (flag2) + { + XSingleton.singleton.AddErrorLog2("same key already exists in the dictionary:{0}", new object[] + { + @object.name + }); + } + else + { + this.m_instanceIDAssetMap.Add(instanceID, uoi); + } + } + return @object; + } + + private void ReturnObject(XResourceLoaderMgr.UniteObjectInfo uoi, UnityEngine.Object obj, int instanceID, bool usePool) + { + bool flag = uoi != null; + if (flag) + { + bool flag2 = uoi.Return(obj, usePool); + if (flag2) + { + bool flag3 = this.m_degenerationQueue == null; + if (flag3) + { + this.m_degenerationQueue = uoi; + this.m_currentDegeneration = uoi; + } + else + { + bool flag4 = this.m_currentDegeneration != null; + if (flag4) + { + this.m_currentDegeneration.next = uoi; + this.m_currentDegeneration = uoi; + } + else + { + this.ReturnObject(uoi); + } + } + this.m_instanceIDAssetMap.Remove(instanceID); + } + else + { + bool flag5 = !uoi.IsSharedResource; + if (flag5) + { + this.m_instanceIDAssetMap.Remove(instanceID); + } + } + } + else + { + bool flag6 = XResourceLoaderMgr.UniteObjectInfo.CanDestroy(obj); + if (flag6) + { + UnityEngine.Object.Destroy(obj); + } + else + { + Resources.UnloadAsset(obj); + } + } + } + + private void ReturnObject(XResourceLoaderMgr.UniteObjectInfo uoi) + { + bool isDegeneration = uoi.IsDegeneration; + if (isDegeneration) + { + this.m_assetPool.Remove(uoi.hashID); + uoi.Clear(); + this.m_objInfoPool.Enqueue(uoi); + } + } + + private XResourceLoaderMgr.UniteObjectInfo GetObjectInfo() + { + bool flag = this.m_objInfoPool.Count > 0; + XResourceLoaderMgr.UniteObjectInfo result; + if (flag) + { + result = this.m_objInfoPool.Dequeue(); + } + else + { + result = new XResourceLoaderMgr.UniteObjectInfo(); + } + return result; + } + + private void PushLoadTask(uint hash, out LoadAsyncTask task) + { + this.isCurrentLoading = true; + LoadAsyncTask loadAsyncTask = null; + int count = this._async_task_list.Count; + int i; + for (i = 0; i < count; i++) + { + LoadAsyncTask loadAsyncTask2 = this._async_task_list[i]; + bool flag = loadAsyncTask2.loadState == EAsyncLoadState.EFree; + if (flag) + { + loadAsyncTask = loadAsyncTask2; + } + else + { + bool flag2 = loadAsyncTask2.hash == hash; + if (flag2) + { + task = loadAsyncTask2; + return; + } + } + } + bool flag3 = loadAsyncTask == null; + if (flag3) + { + for (i++; i < count; i++) + { + LoadAsyncTask loadAsyncTask3 = this._async_task_list[i]; + bool flag4 = loadAsyncTask3.loadState == EAsyncLoadState.EFree; + if (flag4) + { + loadAsyncTask = loadAsyncTask3; + break; + } + } + } + bool flag5 = loadAsyncTask == null; + if (flag5) + { + loadAsyncTask = new LoadAsyncTask(); + this._async_task_list.Add(loadAsyncTask); + } + task = loadAsyncTask; + task.Clear(); + task.loadState = EAsyncLoadState.EPreLoading; + } + + private LoadAsyncTask CreateAsyncTask(string location, string suffix, uint hash, LoadCallBack Cb, object cbOjb, bool sharedRes, bool usePool, Type t) + { + LoadAsyncTask loadAsyncTask; + this.PushLoadTask(hash, out loadAsyncTask); + LoadInfo item; + item.loadCb = Cb; + item.usePool = usePool; + loadAsyncTask.loadType = t; + loadAsyncTask.hash = hash; + loadAsyncTask.location = location; + loadAsyncTask.ext = suffix; + loadAsyncTask.isSharedRes = sharedRes; + loadAsyncTask.cbObj = cbOjb; + loadAsyncTask.loadCbList.Add(item); + return loadAsyncTask; + } + + public GameObject CreateFromPrefab(string location, Vector3 position, Quaternion quaternion, bool usePool = true, bool dontDestroy = false) + { + GameObject gameObject = this.CreateFromPrefab(location, usePool, dontDestroy) as GameObject; + gameObject.transform.position = position; + gameObject.transform.rotation = quaternion; + return gameObject; + } + + public UnityEngine.Object CreateFromPrefab(string location, bool usePool = true, bool dontDestroy = false) + { + return this.CreateFromAsset(location, ".prefab", usePool, dontDestroy); + } + + public T CreateFromAsset(string location, string suffix, bool usePool = true, bool dontDestroy = false) where T : UnityEngine.Object + { + uint num = this.Hash(location, suffix); + bool flag = this.useNewMgr; + T result; + if (flag) + { + UnityEngine.Object @object = null; + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = this.GetUOI(num, out @object, usePool); + bool flag2 = uniteObjectInfo == null; + if (flag2) + { + uniteObjectInfo = this.GetObjectInfo(); + bool flag3 = uniteObjectInfo.Init(location, suffix, num, false, typeof(T), true); + if (flag3) + { + @object = uniteObjectInfo.Get(usePool, false); + } + this.m_assetPool.Add(num, uniteObjectInfo); + } + uniteObjectInfo.IsDontDestroyAsset = dontDestroy; + bool flag4 = @object != null; + if (flag4) + { + this.m_instanceIDAssetMap.Add(@object.GetInstanceID(), uniteObjectInfo); + } + result = (@object as T); + } + else + { + float time = Time.time; + UnityEngine.Object object2 = null; + bool flag5 = usePool && this.GetInObjectPool(ref object2, num); + UnityEngine.Object object3; + if (flag5) + { + object3 = object2; + } + else + { + object2 = this.GetAssetInPool(num); + bool flag6 = object2 == null; + if (flag6) + { + AssetBundleInfo assetBundleInfo = null; + bool flag7 = XSingleton.singleton.ABManager != null; + if (flag7) + { + assetBundleInfo = XSingleton.singleton.ABManager.LoadImm(num, location, suffix, null); + } + bool flag8 = assetBundleInfo != null; + if (flag8) + { + object2 = this.CreateFromAssetBundle(location, num, assetBundleInfo, true); + } + else + { + object2 = this.CreateFromAssets(location, num, true); + } + } + object3 = ((object2 != null) ? XCommon.Instantiate(object2) : null); + bool flag9 = object3 != null; + if (flag9) + { + this.AssetsRefRetain(num); + this.LogReverseID(object3, num); + } + bool flag10 = XSingleton.singleton.EnableRecord(); + if (flag10) + { + XSingleton.singleton.AddPoint(num, location, Time.time - time, 0, XDebug.RecordChannel.EResourceLoad); + } + } + result = (object3 as T); + } + return result; + } + + public LoadAsyncTask CreateFromPrefabAsync(string location, LoadCallBack Cb, object cbOjb, bool usePool = true) + { + uint num = this.Hash(location, ".prefab"); + bool flag = this.useNewMgr; + LoadAsyncTask result; + if (flag) + { + UnityEngine.Object obj = null; + XResourceLoaderMgr.UniteObjectInfo uoi = this.GetUOI(num, out obj, usePool); + bool flag2 = uoi != null; + if (flag2) + { + Cb(obj, cbOjb); + result = null; + } + else + { + result = this.CreateAsyncTask(location, ".prefab", num, Cb, cbOjb, false, usePool, typeof(GameObject)); + } + } + else + { + UnityEngine.Object @object = null; + bool flag3 = usePool && this.GetInObjectPool(ref @object, num); + if (flag3) + { + Cb(@object, cbOjb); + result = null; + } + else + { + bool flag4 = !this._asset_pool.TryGetValue(num, out @object); + if (flag4) + { + result = this.CreateAsyncTask(location, ".prefab", num, Cb, cbOjb, false, usePool, typeof(GameObject)); + } + else + { + LoadAsyncTask loadAsyncTask = this.CreateAsyncTask(location, ".prefab", num, Cb, cbOjb, false, usePool, typeof(GameObject)); + loadAsyncTask.asset = @object; + loadAsyncTask.loadState = EAsyncLoadState.EInstance; + result = loadAsyncTask; + } + } + } + return result; + } + + public T GetSharedResource(string location, string suffix, bool canNotNull = true, bool preload = false) where T : UnityEngine.Object + { + uint num = this.Hash(location, suffix); + bool flag = this.useNewMgr; + T result; + if (flag) + { + UnityEngine.Object @object = null; + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = this.GetUOI(num, out @object, false); + bool flag2 = uniteObjectInfo == null; + if (flag2) + { + uniteObjectInfo = this.GetObjectInfo(); + uniteObjectInfo.IsDontDestroyAsset = this.dontDestroy; + bool flag3 = uniteObjectInfo.Init(location, suffix, num, true, typeof(T), canNotNull); + if (flag3) + { + @object = uniteObjectInfo.Get(preload, false); + } + else + { + bool flag4 = !canNotNull; + if (flag4) + { + this.m_objInfoPool.Enqueue(uniteObjectInfo); + return default(T); + } + } + this.m_assetPool.Add(num, uniteObjectInfo); + bool flag5 = @object != null; + if (flag5) + { + this.m_instanceIDAssetMap.Add(@object.GetInstanceID(), uniteObjectInfo); + } + } + result = (@object as T); + } + else + { + float time = Time.time; + UnityEngine.Object object2 = this.GetAssetInPool(num); + bool flag6 = object2 == null; + if (flag6) + { + AssetBundleInfo assetBundleInfo = null; + bool flag7 = XSingleton.singleton.ABManager != null; + if (flag7) + { + assetBundleInfo = XSingleton.singleton.ABManager.LoadImm(num, location, suffix, null); + } + bool flag8 = assetBundleInfo != null; + if (flag8) + { + object2 = this.CreateFromAssetBundle(location, num, assetBundleInfo, canNotNull); + } + else + { + object2 = this.CreateFromAssets(location, num, canNotNull); + } + } + bool flag9 = object2 != null; + if (flag9) + { + this.AssetsRefRetain(num); + } + bool flag10 = XSingleton.singleton.EnableRecord(); + if (flag10) + { + XSingleton.singleton.AddPoint(num, location, Time.time - time, 1, XDebug.RecordChannel.EResourceLoad); + } + result = (object2 as T); + } + return result; + } + + public LoadAsyncTask GetShareResourceAsync(string location, string suffix, LoadCallBack Cb, object cbOjb) where T : UnityEngine.Object + { + uint num = this.Hash(location, suffix); + bool flag = this.useNewMgr; + LoadAsyncTask result; + if (flag) + { + UnityEngine.Object obj = null; + XResourceLoaderMgr.UniteObjectInfo uoi = this.GetUOI(num, out obj, false); + bool flag2 = uoi != null; + if (flag2) + { + Cb(obj, cbOjb); + result = null; + } + else + { + result = this.CreateAsyncTask(location, suffix, num, Cb, null, true, false, typeof(T)); + } + } + else + { + UnityEngine.Object obj2 = null; + bool flag3 = this._asset_pool.TryGetValue(num, out obj2); + if (flag3) + { + Cb(obj2, cbOjb); + this.AssetsRefRetain(num); + result = null; + } + else + { + result = this.CreateAsyncTask(location, suffix, num, Cb, cbOjb, true, false, typeof(T)); + } + } + return result; + } + + public XAnimationClip GetXAnimation(string location, bool showLog = true, bool preload = false) + { + uint num = this.Hash(location, ".anim"); + bool flag = this.useNewMgr; + XAnimationClip result; + if (flag) + { + UnityEngine.Object @object = null; + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = this.GetUOI(num, out @object, false); + bool flag2 = uniteObjectInfo == null; + if (flag2) + { + uniteObjectInfo = this.GetObjectInfo(); + bool flag3 = uniteObjectInfo.InitAnim(location, ".anim", num); + if (flag3) + { + @object = uniteObjectInfo.Get(false, preload); + } + this.m_assetPool.Add(num, uniteObjectInfo); + bool flag4 = @object != null; + if (flag4) + { + this.m_instanceIDAssetMap.Add(@object.GetInstanceID(), uniteObjectInfo); + } + } + result = (@object as XAnimationClip); + } + else + { + UnityEngine.Object object2 = this.GetAssetInPool(num); + bool flag5 = object2 == null; + if (flag5) + { + AssetBundleInfo assetBundleInfo = null; + bool flag6 = XSingleton.singleton.ABManager != null; + if (flag6) + { + assetBundleInfo = XSingleton.singleton.ABManager.LoadImm(num, location, ".anim", null); + } + bool flag7 = assetBundleInfo != null; + if (flag7) + { + object2 = this.CreateFromAssetBundle(location, num, assetBundleInfo, showLog); + } + else + { + object2 = this.CreateFromAssets(location, num, showLog); + } + } + bool flag8 = object2 != null; + if (flag8) + { + this.AssetsRefRetain(num); + } + result = (object2 as XAnimationClip); + } + return result; + } + + public static void SafeGetAnimationClip(string location, ref XAnimationClip clip) + { + bool flag = clip != null; + if (flag) + { + XSingleton.singleton.UnSafeDestroyShareResource(location, ".anim", clip, false); + clip = null; + } + clip = XSingleton.singleton.GetXAnimation(location, true, false); + } + + public static void SafeDestroy(ref UnityEngine.Object obj, bool returnPool = true) + { + XSingleton.singleton.UnSafeDestroy(obj, returnPool, false); + obj = null; + } + + public static void SafeDestroy(ref GameObject obj, bool returnPool = true) + { + XSingleton.singleton.UnSafeDestroy(obj, returnPool, false); + obj = null; + } + + public static void SafeDestroyShareResource(string location, ref GameObject obj, bool triggerRelease = false) + { + XSingleton.singleton.UnSafeDestroyShareResource(location, ".prefab", obj, triggerRelease); + obj = null; + } + + public static void SafeDestroyShareResource(string location, ref Material obj) + { + XSingleton.singleton.UnSafeDestroyShareResource(location, ".mat", obj, false); + obj = null; + } + + public static void SafeDestroyShareResource(string location, ref XAnimationClip obj) + { + bool flag = obj != null; + if (flag) + { + XSingleton.singleton.UnSafeDestroyShareResource(location, ".anim", obj.clip, false); + obj = null; + } + } + + private void InnerDestroy(UnityEngine.Object obj, int instanceID, bool sharedRes) + { + XResourceLoaderMgr.UniteObjectInfo uoi = null; + bool flag = this.m_instanceIDAssetMap.TryGetValue(instanceID, out uoi); + if (flag) + { + this.ReturnObject(uoi, obj, instanceID, false); + } + else if (sharedRes) + { + bool flag2 = !XResourceLoaderMgr.UniteObjectInfo.CanDestroy(obj); + if (flag2) + { + Resources.UnloadAsset(obj); + } + } + else + { + bool flag3 = XResourceLoaderMgr.UniteObjectInfo.CanDestroy(obj); + if (flag3) + { + UnityEngine.Object.Destroy(obj); + } + } + } + + public void UnSafeDestroy(UnityEngine.Object o, bool returnPool = true, bool destroyImm = false) + { + bool flag = o == null; + if (!flag) + { + int instanceID = o.GetInstanceID(); + bool flag2 = this.useNewMgr; + if (flag2) + { + this.InnerDestroy(o, instanceID, false); + } + else + { + uint num = 0u; + bool flag3 = returnPool && this._reverse_map.TryGetValue(instanceID, out num); + if (flag3) + { + this.AddToObjectPool(num, o); + } + else + { + bool flag4 = this._reverse_map.TryGetValue(instanceID, out num); + if (flag4) + { + this.AssetsRefRelease(num); + this._reverse_map.Remove(instanceID); + } + if (destroyImm) + { + UnityEngine.Object.DestroyImmediate(o); + } + else + { + UnityEngine.Object.Destroy(o); + } + } + } + } + } + + public void UnSafeDestroyShareResource(string location, string suffix, UnityEngine.Object o, bool triggerRelease = false) + { + bool flag = o == null; + if (!flag) + { + bool flag2 = this.useNewMgr; + if (flag2) + { + int instanceID = o.GetInstanceID(); + this.InnerDestroy(o, instanceID, true); + } + else + { + bool flag3 = !string.IsNullOrEmpty(location); + if (flag3) + { + uint num = this.Hash(location, suffix); + bool flag4 = this._asset_ref_count.ContainsKey(num); + if (flag4) + { + bool flag5 = this.AssetsRefRelease(num) && triggerRelease && !XResourceLoaderMgr.UniteObjectInfo.CanDestroy(o); + if (flag5) + { + Resources.UnloadAsset(o); + } + } + else + { + bool flag6 = !XResourceLoaderMgr.UniteObjectInfo.CanDestroy(o); + if (flag6) + { + bool flag7 = !(XSingleton.singleton.ABManager != null) || !XSingleton.singleton.ABManager.CheckInDep(num); + if (flag7) + { + Resources.UnloadAsset(o); + } + } + } + } + } + } + } + + private void DelayDestroy(float deltaTime, bool force) + { + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo = this.m_degenerationQueue; + this.m_degenerationQueue = null; + XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo2 = null; + while (uniteObjectInfo != null) + { + XResourceLoaderMgr.UniteObjectInfo next = uniteObjectInfo.next; + uniteObjectInfo.degenerationTime += deltaTime; + bool flag = force || !uniteObjectInfo.IsDegeneration || uniteObjectInfo.degenerationTime > 2f; + if (flag) + { + bool flag2 = uniteObjectInfo2 != null; + if (flag2) + { + uniteObjectInfo2.next = uniteObjectInfo.next; + } + this.ReturnObject(uniteObjectInfo); + } + else + { + uniteObjectInfo2 = uniteObjectInfo; + bool flag3 = this.m_degenerationQueue == null; + if (flag3) + { + this.m_degenerationQueue = uniteObjectInfo; + } + } + uniteObjectInfo = next; + } + this.m_currentDegeneration = this.m_degenerationQueue; + while (this.m_currentDegeneration != null && this.m_currentDegeneration.next != null) + { + this.m_currentDegeneration = this.m_currentDegeneration.next; + } + } + + public void LoadABScene(string path) + { + uint hash = 0u; + hash = XSingleton.singleton.XHashLowerRelpaceDot(hash, "Assets.XScene.Scenelib."); + hash = XSingleton.singleton.XHashLowerRelpaceDot(hash, path); + hash = XSingleton.singleton.XHashLowerRelpaceDot(hash, ".unity"); + AssetBundleInfo assetBundleInfo = XSingleton.singleton.ABManager.LoadImm(hash, path, ".unity", "Assets.XScene.Scenelib."); + bool flag = assetBundleInfo != null; + if (flag) + { + XSingleton.singleton.AddLog("Load AB Scene Finish!", null, null, null, null, null, XDebugColor.XDebug_None); + } + } + + public IXCurve GetCurve(string location) + { + bool useCurveTable = XResourceLoaderMgr.UseCurveTable; + IXCurve result; + if (useCurveTable) + { + uint num = XSingleton.singleton.XHash(location); + IXCurve ixcurve = this.GetServerCurve(num); + bool flag = ixcurve == null; + if (flag) + { + XSingleton.singleton.AddLog2("curve not found:{0}|Hash:{1}", new object[] + { + location, + num + }); + GameObject sharedResource = this.GetSharedResource(location, ".prefab", true, false); + ixcurve = (sharedResource.GetComponent("XCurve") as IXCurve); + } + result = ixcurve; + } + else + { + GameObject sharedResource2 = this.GetSharedResource(location, ".prefab", true, false); + result = (sharedResource2.GetComponent("XCurve") as IXCurve); + } + return result; + } + + private FloatCurve _GetFloatCurve(uint hash) + { + int i = 0; + int num = this.m_curveData.Count - 1; + while (i <= num) + { + int num2 = (i + num) / 2; + bool flag = hash > this.m_curveData[num2].namehash; + if (flag) + { + i = num2 + 1; + } + else + { + bool flag2 = hash < this.m_curveData[num2].namehash; + if (!flag2) + { + return this.m_curveData[num2]; + } + num = num2 - 1; + } + } + return null; + } + + public FloatCurve GetServerCurve(uint hash) + { + return this._GetFloatCurve(hash); + } + + public T GetData(string pathwithname, string suffix) + { + uint key = XSingleton.singleton.XHash(pathwithname); + UnityEngine.Object @object = null; + bool flag = !this._script_pool.TryGetValue(key, out @object); + if (flag) + { + TextAsset sharedResource = this.GetSharedResource(pathwithname, suffix, true, false); + bool flag2 = sharedResource == null; + if (flag2) + { + XSingleton.singleton.AddErrorLog("Deserialize file ", pathwithname, " Error!", null, null, null); + } + int num = (typeof(T) == typeof(XCutSceneData)) ? 1 : 0; + XmlSerializer xmlSerializer = this.xmlSerializerCache[num]; + this.shareMemoryStream.Seek(0L, SeekOrigin.Begin); + this.shareMemoryStream.SetLength(0L); + this.shareMemoryStream.Write(sharedResource.bytes, 0, sharedResource.bytes.Length); + this.shareMemoryStream.Seek(0L, SeekOrigin.Begin); + object data = xmlSerializer.Deserialize(this.shareMemoryStream); + XDataWrapper xdataWrapper = ScriptableObject.CreateInstance(); + xdataWrapper.Data = data; + this.UnSafeDestroyShareResource(pathwithname, suffix, sharedResource, false); + @object = xdataWrapper; + bool flag3 = null != @object; + if (flag3) + { + this._script_pool.Add(key, @object); + } + } + return (T)((object)(@object as XDataWrapper).Data); + } + + public UnityEngine.Object AddAssetInPool(UnityEngine.Object asset, uint hash, AssetBundleInfo info = null) + { + bool flag = asset == null; + UnityEngine.Object result; + if (flag) + { + result = null; + } + else + { + UnityEngine.Object @object = null; + this._asset_pool.TryGetValue(hash, out @object); + bool flag2 = @object == null; + if (flag2) + { + @object = asset; + this._asset_pool[hash] = @object; + bool flag3 = info != null && !this._bundle_pool.ContainsKey(hash); + if (flag3) + { + info.Retain(); + this._bundle_pool.Add(hash, info); + } + } + result = @object; + } + return result; + } + + public UnityEngine.Object GetAssetInPool(uint hash) + { + UnityEngine.Object result = null; + this._asset_pool.TryGetValue(hash, out result); + return result; + } + + public bool GetInObjectPool(ref UnityEngine.Object o, uint id) + { + Queue queue = null; + bool flag = this._object_pool.TryGetValue(id, out queue); + if (flag) + { + int count = queue.Count; + bool flag2 = count > 0; + if (flag2) + { + UnityEngine.Object @object = queue.Dequeue(); + while (@object == null && queue.Count > 0) + { + @object = queue.Dequeue(); + } + bool flag3 = @object == null; + if (flag3) + { + return false; + } + o = @object; + return true; + } + } + return false; + } + + private UnityEngine.Object CreateFromAssets(string location, uint hash, bool showError = true) + { + bool flag = typeof(T) == typeof(XAnimationClip); + UnityEngine.Object @object; + if (flag) + { + XAnimationClip xanimationClip = XAnimationPool.Get(); + xanimationClip.clip = (Resources.Load(location, typeof(AnimationClip)) as AnimationClip); + bool flag2 = xanimationClip.clip == null; + if (flag2) + { + if (showError) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + return null; + } + xanimationClip.length = xanimationClip.clip.length; + @object = xanimationClip; + } + else + { + @object = Resources.Load(location, typeof(T)); + } + XResourceLoaderMgr.resourceLoadCount++; + @object = this.AddAssetInPool(@object, hash, null); + bool flag3 = @object == null; + UnityEngine.Object result; + if (flag3) + { + if (showError) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + result = null; + } + else + { + result = @object; + } + return result; + } + + private UnityEngine.Object CreateFromAssetBundle(string location, uint hash, AssetBundleInfo info, bool showError = true) + { + bool flag = typeof(T) == typeof(XAnimationClip); + UnityEngine.Object @object; + if (flag) + { + XAnimationClip xanimationClip = XAnimationPool.Get(); + xanimationClip.clip = (info.mainObject as AnimationClip); + bool flag2 = xanimationClip.clip == null; + if (flag2) + { + if (showError) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + return null; + } + xanimationClip.length = xanimationClip.clip.length; + @object = xanimationClip; + } + else + { + @object = info.mainObject; + } + XResourceLoaderMgr.abLoadCount++; + @object = this.AddAssetInPool(@object, hash, info); + bool flag3 = @object == null; + UnityEngine.Object result; + if (flag3) + { + if (showError) + { + XResourceLoaderMgr.LoadErrorLog(location); + } + result = null; + } + else + { + result = @object; + } + return result; + } + + private void AddToObjectPool(uint id, UnityEngine.Object obj) + { + Queue queue = null; + bool flag = !this._object_pool.TryGetValue(id, out queue); + if (flag) + { + queue = new Queue(); + this._object_pool.Add(id, queue); + } + GameObject gameObject = obj as GameObject; + bool flag2 = gameObject != null; + if (flag2) + { + Transform transform = gameObject.transform; + transform.position = XResourceLoaderMgr.Far_Far_Away; + transform.rotation = Quaternion.identity; + transform.parent = null; + } + queue.Enqueue(obj); + } + + public void AssetsRefRetain(uint hash) + { + int num = 0; + this._asset_ref_count.TryGetValue(hash, out num); + num++; + this._asset_ref_count[hash] = num; + } + + public bool AssetsRefRelease(uint hash) + { + int num = 0; + bool flag = this._asset_ref_count.TryGetValue(hash, out num); + if (flag) + { + num--; + bool flag2 = num < 0; + if (flag2) + { + num = 0; + } + bool flag3 = num == 0; + if (flag3) + { + this._asset_pool.Remove(hash); + this._asset_ref_count.Remove(hash); + AssetBundleInfo assetBundleInfo = null; + bool flag4 = this._bundle_pool.TryGetValue(hash, out assetBundleInfo); + if (flag4) + { + assetBundleInfo.Release(); + this._bundle_pool.Remove(hash); + return false; + } + return true; + } + else + { + this._asset_ref_count[hash] = num; + } + } + return false; + } + + public void LogReverseID(UnityEngine.Object o, uint id) + { + bool flag = o != null; + if (flag) + { + int instanceID = o.GetInstanceID(); + bool flag2 = !this._reverse_map.ContainsKey(instanceID); + if (flag2) + { + this._reverse_map.Add(instanceID, id); + } + } + } + + public static void LoadErrorLog(string prefab) + { + XSingleton.singleton.AddErrorLog("Load resource: ", prefab, " error!", null, null, null); + } + + public void Update(float deltaTime) + { + bool flag = false; + bool flag2 = true; + float time = Time.time; + for (int i = 0; i < this._async_task_list.Count; i++) + { + LoadAsyncTask loadAsyncTask = this._async_task_list[i]; + bool flag3 = flag2; + if (flag3) + { + bool flag4 = loadAsyncTask.Update(); + if (flag4) + { + loadAsyncTask.Clear(); + } + float num = Time.time - time; + bool flag5 = num >= this.maxLoadThresholdTime; + if (flag5) + { + flag2 = false; + } + } + flag |= (loadAsyncTask.loadState == EAsyncLoadState.ELoading); + } + bool flag6 = !flag; + if (flag6) + { + this.isCurrentLoading = false; + } + this.DelayDestroy(deltaTime, false); + this.UpdateDelayProcess(deltaTime); + } + + public void AddDelayProcess(IDelayLoad loader) + { + int i = 0; + int count = this.delayUpdateList.Count; + while (i < count) + { + IDelayLoad delayLoad = this.delayUpdateList[i]; + bool flag = delayLoad == loader; + if (flag) + { + return; + } + i++; + } + bool flag2 = this.currentDelayTime < 0.0; + if (flag2) + { + this.currentDelayTime = XResourceLoaderMgr.delayTime; + } + this.delayUpdateList.Add(loader); + } + + public void RemoveDelayProcess(IDelayLoad loader) + { + this.delayUpdateList.Remove(loader); + } + + public void UpdateDelayProcess(float deltaTime) + { + bool flag = this.delayUpdateList.Count > 0; + if (flag) + { + this.currentDelayTime -= XResourceLoaderMgr.delayTime; + bool flag2 = this.currentDelayTime <= 0.0; + if (flag2) + { + IDelayLoad delayLoad = this.delayUpdateList[0]; + EDelayProcessType edelayProcessType = delayLoad.DelayUpdate(); + bool flag3 = edelayProcessType == EDelayProcessType.EFinish; + if (flag3) + { + this.delayUpdateList.RemoveAt(0); + bool flag4 = this.delayUpdateList.Count > 0; + if (flag4) + { + this.currentDelayTime = XResourceLoaderMgr.delayTime; + } + } + } + } + } + } +} -- cgit v1.1-26-g67d0