using System.Collections; using System.Collections.Generic; using UnityEngine; public class ResourLoadMananger : MonoBehaviour { private static ResourLoadMananger instance; public static ResourLoadMananger GetInstance() { if(instance==null) { instance = new GameObject("ResourLoadMananger").AddComponent(); } return instance; } private Hashtable ht = null; void Awake() { ht = new Hashtable(); } /// /// 调用资源(带对象缓冲技术) /// /// /// /// /// public T LoadResource(string path, bool isCatch) where T : UnityEngine.Object { if (ht.Contains(path)) { return ht[path] as T; } T TResource = Resources.Load(path); if (TResource == null) { Debug.LogError(GetType() + "/GetInstance()/TResource 提取的资源找不到,请检查。 path=" + path); } else if (isCatch) { ht.Add(path, TResource); } return TResource; } /// /// 调用资源 /// /// /// /// public GameObject LoadAsset(string path, bool isCatch) { GameObject goObj = LoadResource(path, isCatch); GameObject goObjClone = GameObject.Instantiate(goObj); if (goObjClone == null) { Debug.LogError(GetType() + "/LoadAsset()/克隆资源不成功,请检查。 path=" + path); } //goObj = null;//?????????? return goObjClone; } }