using System; using System.Collections; using System.Diagnostics; using UnityEngine; public class ResMgr : MonoBehaviour { public delegate void LoadAyncCallback(UnityEngine.Object obj); public const string TAG = "ResMgr"; private static ResMgr m_Instance; public static ResMgr Instance { get { if (null == ResMgr.m_Instance) { GameObject gameObject = GameObject.Find("ResMgr"); if (null == gameObject) { gameObject = new GameObject("ResMgr"); gameObject.transform.localPosition = new Vector3(1000f, 0f, 0f); DontDestroyOnLoad(gameObject); } ResMgr.m_Instance = gameObject.AddComponent(); } return ResMgr.m_Instance; } } public void Init() { } public UnityEngine.Object Load(string assetName) { #if UNITY_EDITOR return Resources.Load(assetName); #else return GameInit.ablist.LoadAsset(assetName); #endif } public T Load(string assetName) where T : UnityEngine.Object { #if UNITY_EDITOR return Resources.Load(assetName); #else return GameInit.ablist.LoadAsset(assetName); #endif // } public ResourceRequest LoadAsync(string assetName) { // return GameInit.ablist(assetName); return Resources.LoadAsync(assetName); } public ResourceRequest LoadAsync(string assetName) where T : UnityEngine.Object { #if UNITY_EDITOR return Resources.LoadAsync(assetName); #else return GameInit.ablist.LoadAssetAsync(assetName); #endif } public void LoadAsync(string assetName, ResMgr.LoadAyncCallback callback) { //base.StartCoroutine(this.ResourcesLoadAsync(assetName, callback)); } [DebuggerHidden] //private IEnumerator ResourcesLoadAsync(string assetName, ResMgr.LoadAyncCallback callback) //{ // ResMgr.c__Iterator0 c__Iterator = new ResMgr.c__Iterator0(); // c__Iterator.assetName = assetName; // c__Iterator.callback = callback; // return c__Iterator; //} public Sprite GetSprite(string name) { if (string.IsNullOrEmpty(name)) { return null; } GameObject gameObject = this.Load(name); if (null == gameObject) { return null; } SpriteRenderer component = gameObject.GetComponent(); if (null == component) { return null; } return component.sprite; } public void GetSpriteAsync(string name, Action callback) { if (!string.IsNullOrEmpty(name)) { this.LoadAsync(name, delegate (UnityEngine.Object obj) { if (callback == null) { return; } GameObject gameObject = obj as GameObject; Sprite obj2 = null; if (null != gameObject) { SpriteRenderer component = gameObject.GetComponent(); if (null != component) { obj2 = component.sprite; } } callback(obj2); }); } } }