using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; public static class ResourcesManager { /// /// 同步加载 /// /// public static T Load(string resName) where T : Object { T res = Resources.Load(resName); if (res is GameObject) { return GameObject.Instantiate(res); } else return res; } /// /// 异步加载 /// /// public static void LoadAsync( MonoBehaviour target,string resName, UnityAction action) where T : Object { target.StartCoroutine(RealLoadAsync(resName, action)); } /// /// 真正的异步加载过程 /// /// /// /// /// private static IEnumerator RealLoadAsync(string resName, UnityAction action) where T : Object { ResourceRequest request = Resources.LoadAsync(resName); yield return request; if (request.asset is GameObject) { action(GameObject.Instantiate(request.asset) as T); } else { action(request.asset as T); } } }