ResourcesManager

来源:互联网 发布:京麦工作台和淘宝助理 编辑:程序博客网 时间:2024/05/22 03:35
using System.Collections;using System.Collections.Generic;using UnityEngine;public class ResourcesManager {        private static ResourcesManager _Instance = null;        public static ResourcesManager Instance        {            get            {                if (_Instance == null)                {                    _Instance = new ResourcesManager();                }                return _Instance;            }        }    private string jsonPath = "Config";    public TextAsset GetJsonText(string name)    {        return LoadJsonAsset(jsonPath,name);    }    public TextAsset LoadJsonAsset(string path,string name)    {        TextAsset textAsset = null;        string loadPath=path+"/"+name;        textAsset = Resources.Load(loadPath,typeof(TextAsset))as TextAsset;        if (textAsset == null)        {            Debug.Log("加载路径出错:" + loadPath);            return null;        }        return textAsset;    }    private string uiPrefabPath = "UI/Panel";    public GameObject GetUIPrefab(string name)    {        return LoadPrefab(name, uiPrefabPath);    }    public GameObject LoadPrefab(string name, string path)    {        string loadPath = path + "/" + name;        GameObject prefab = Resources.Load(loadPath, typeof(GameObject)) as GameObject;        if (prefab == null)        {            Debug.LogError("prefab is not exist:" + loadPath);        }        return prefab;    }}

0 0
原创粉丝点击