Manager Of Managers(九)JsonManager

    技术2024-12-29  27

    //========================== // - FileName: JsonManager.cs // - Created: true. // - CreateTime: 2020/06/26 00:37:09 // - Email: 1670328571@qq.com // - Region: China WUHAN // - Description: Json 读取 //========================== using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class JsonUtilityManager:BaseManager { /构造函数 public JsonUtilityManager(GameManager gameManager) : base(gameManager) { //ParseUIPanelTypeJson(); } private Dictionary<UIPanelType, string> panelPathDict;//存储所有面板Prefab的路径 ///序列化json对象(必须有) [Serializable] class UIPanelTypeJson { public List<UIPanelInfo> infoList;//这个名字要和json数据中的对象对应 } ///读取json对象的内容 private void ParseUIPanelTypeJson() { panelPathDict = new Dictionary<UIPanelType, string>(); TextAsset ta = Resources.Load<TextAsset>("Json/UIPanelType"); UIPanelTypeJson jsonObject = JsonUtility.FromJson<UIPanelTypeJson>(ta.text); foreach (UIPanelInfo info in jsonObject.infoList) { //Debug.Log(info.panelType); panelPathDict.Add(info.panelType, info.path); } } /// <summary> /// just for test /// </summary> public void Test() { string path; panelPathDict.TryGetValue(UIPanelType.Knapsack, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.ItemMessage, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.MainMenu, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.Shop, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.Skill, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.System, out path); Debug.Log(path); panelPathDict.TryGetValue(UIPanelType.Task, out path); Debug.Log(path); } }
    Processed: 0.009, SQL: 9