using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; namespace I2.Loc { public class ResourceManager : MonoBehaviour { public static ResourceManager pInstance { get { bool flag = ResourceManager.mInstance == null; if (ResourceManager.mInstance == null) { ResourceManager.mInstance = (ResourceManager)UnityEngine.Object.FindObjectOfType(typeof(ResourceManager)); } if (ResourceManager.mInstance == null) { GameObject gameObject = new GameObject("I2ResourceManager", new Type[] { typeof(ResourceManager) }); gameObject.hideFlags |= HideFlags.HideAndDontSave; ResourceManager.mInstance = gameObject.GetComponent(); if (ResourceManager.<>f__mg$cache0 == null) { ResourceManager.<>f__mg$cache0 = new UnityAction(ResourceManager.MyOnLevelWasLoaded); } SceneManager.sceneLoaded += ResourceManager.<>f__mg$cache0; } if (flag && Application.isPlaying) { UnityEngine.Object.DontDestroyOnLoad(ResourceManager.mInstance.gameObject); } return ResourceManager.mInstance; } } public static void MyOnLevelWasLoaded(Scene scene, LoadSceneMode mode) { ResourceManager.pInstance.CleanResourceCache(); LocalizationManager.UpdateSources(); } public T GetAsset(string Name) where T : UnityEngine.Object { T t = this.FindAsset(Name) as T; if (t != null) { return t; } return this.LoadFromResources(Name); } private UnityEngine.Object FindAsset(string Name) { if (this.Assets != null) { int i = 0; int num = this.Assets.Length; while (i < num) { if (this.Assets[i] != null && this.Assets[i].name == Name) { return this.Assets[i]; } i++; } } return null; } public bool HasAsset(UnityEngine.Object Obj) { return this.Assets != null && Array.IndexOf(this.Assets, Obj) >= 0; } public T LoadFromResources(string Path) where T : UnityEngine.Object { T result; try { UnityEngine.Object @object; if (string.IsNullOrEmpty(Path)) { result = (T)((object)null); } else if (this.mResourcesCache.TryGetValue(Path, out @object) && @object != null) { result = (@object as T); } else { T t = (T)((object)null); if (Path.EndsWith("]", StringComparison.OrdinalIgnoreCase)) { int num = Path.LastIndexOf("[", StringComparison.OrdinalIgnoreCase); int length = Path.Length - num - 2; string value = Path.Substring(num + 1, length); Path = Path.Substring(0, num); T[] array = Resources.LoadAll(Path); int i = 0; int num2 = array.Length; while (i < num2) { if (array[i].name.Equals(value)) { t = array[i]; break; } i++; } } else { t = (Resources.Load(Path, typeof(T)) as T); } if (t == null) { t = this.LoadFromBundle(Path); } if (t != null) { this.mResourcesCache[Path] = t; } result = t; } } catch (Exception ex) { Debug.LogErrorFormat("Unable to load {0} '{1}'\nERROR: {2}", new object[] { typeof(T), Path, ex.ToString() }); result = (T)((object)null); } return result; } public T LoadFromBundle(string path) where T : UnityEngine.Object { int i = 0; int count = this.mBundleManagers.Count; while (i < count) { if (this.mBundleManagers[i] != null) { T t = this.mBundleManagers[i].LoadFromBundle(path, typeof(T)) as T; if (t != null) { return t; } } i++; } return (T)((object)null); } public void CleanResourceCache() { this.mResourcesCache.Clear(); Resources.UnloadUnusedAssets(); base.CancelInvoke(); } private static ResourceManager mInstance; public List mBundleManagers = new List(); public UnityEngine.Object[] Assets; private readonly Dictionary mResourcesCache = new Dictionary(StringComparer.Ordinal); [CompilerGenerated] private static UnityAction <>f__mg$cache0; } }