using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; public class ResourceManager : BaseManager { public T Load(string name) where T : Object { T res = Resources.Load(name); return res; } public void LoadAsync(string name, UnityAction action = null) where T : Object { MonoManager.GetInstance().StartCoroutine(ReallyLoadResourceAsyn(name, action)); } private IEnumerator ReallyLoadResourceAsyn(string name, UnityAction action = null) where T : Object { ResourceRequest r = Resources.LoadAsync(name); yield return r; if (r.asset != null) { if (action != null) { if (r.asset is GameObject) { action((GameObject.Instantiate(r.asset)) as T); } else { action(r.asset as T); } } } else { Debug.Log(name + ": null"); } } }