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<ResMgr>();
            }
            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<T>(string assetName) where T : UnityEngine.Object
    {
        #if UNITY_EDITOR
                return Resources.Load<T>(assetName);
        #else
                return GameInit.ablist.LoadAsset<T>(assetName);
        #endif
        // 
    }
    public ResourceRequest LoadAsync(string assetName)
    {
      //  return GameInit.ablist(assetName);
        return Resources.LoadAsync(assetName);
    }
    public ResourceRequest LoadAsync<T>(string assetName) where T : UnityEngine.Object
    {

        return Resources.LoadAsync<T>(assetName);
    }
    public void LoadAsync(string assetName, ResMgr.LoadAyncCallback callback)
    {
        //base.StartCoroutine(this.ResourcesLoadAsync(assetName, callback));
    }
    [DebuggerHidden]
    //private IEnumerator ResourcesLoadAsync(string assetName, ResMgr.LoadAyncCallback callback)
    //{
    //	ResMgr.<ResourcesLoadAsync>c__Iterator0 <ResourcesLoadAsync>c__Iterator = new ResMgr.<ResourcesLoadAsync>c__Iterator0();
    //	<ResourcesLoadAsync>c__Iterator.assetName = assetName;
    //	<ResourcesLoadAsync>c__Iterator.callback = callback;
    //	return <ResourcesLoadAsync>c__Iterator;
    //}
    public Sprite GetSprite(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return null;
        }
        GameObject gameObject = this.Load<GameObject>(name);
        if (null == gameObject)
        {
            return null;
        }
        SpriteRenderer component = gameObject.GetComponent<SpriteRenderer>();
        if (null == component)
        {
            return null;
        }
        return component.sprite;
    }
    public void GetSpriteAsync(string name, Action<Sprite> 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<SpriteRenderer>();
                    if (null != component)
                    {
                        obj2 = component.sprite;
                    }
                }
                callback(obj2);
            });
        }
    }
}