1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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<ResourLoadMananger>();
- }
- return instance;
- }
- private Hashtable ht = null;
- void Awake()
- {
- ht = new Hashtable();
- }
- /// <summary>
- /// 调用资源(带对象缓冲技术)
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="path"></param>
- /// <param name="isCatch"></param>
- /// <returns></returns>
- public T LoadResource<T>(string path, bool isCatch) where T : UnityEngine.Object
- {
- if (ht.Contains(path))
- {
- return ht[path] as T;
- }
- T TResource = Resources.Load<T>(path);
- if (TResource == null)
- {
- Debug.LogError(GetType() + "/GetInstance()/TResource 提取的资源找不到,请检查。 path=" + path);
- }
- else if (isCatch)
- {
- ht.Add(path, TResource);
- }
- return TResource;
- }
- /// <summary>
- /// 调用资源
- /// </summary>
- /// <param name="path"></param>
- /// <param name="isCatch"></param>
- /// <returns></returns>
- public GameObject LoadAsset(string path, bool isCatch)
- {
- GameObject goObj = LoadResource<GameObject>(path, isCatch);
- GameObject goObjClone = GameObject.Instantiate<GameObject>(goObj);
- if (goObjClone == null)
- {
- Debug.LogError(GetType() + "/LoadAsset()/克隆资源不成功,请检查。 path=" + path);
- }
- //goObj = null;//??????????
- return goObjClone;
- }
- }
|