using System.Collections; using System.Collections.Generic; using System.IO; using cfg; using cfg.BlacksmithData; using SimpleJSON; using UnityEngine; public class JsonTab { private static JsonTab instance; private Dictionary> attribute; public static JsonTab Instance { get { return instance; } } public Tables tables; public JsonTab() // 这是构造函数 { if (instance == null) instance = this; } public void InitData(){ tables = new Tables(Loader); LoadWeaponAttribute(); } private JSONNode Loader(string fileName) { string data = Resources.Load("Data/"+fileName).text; // File.ReadAllText(Application.streamingAssetsPath + "/" + fileName + ".json"); return JSON.Parse(data); } private void LoadWeaponAttribute() { attribute = new Dictionary>(); foreach (var attributeData in JsonTab.Instance.tables.WeaponAttribute.DataList) { if (attribute.ContainsKey(attributeData.Arms)) { attribute[attributeData.Arms][attributeData.Level] = attributeData; } else { attribute[attributeData.Arms] = new Dictionary(); attribute[attributeData.Arms][attributeData.Level] = attributeData; } } } public WeaponAttributeData attributeData(int id,int level) { return attribute[id][level]; } }