2024-12-16 17:25:10 +08:00

63 lines
1.7 KiB
C#

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;
public Dictionary<int, Dictionary<int, WeaponAttributeData>> Attribute => attribute;
private Dictionary<int, Dictionary<int, WeaponAttributeData>> 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<TextAsset>("Data/"+fileName).text;
// File.ReadAllText(Application.streamingAssetsPath + "/" + fileName + ".json");
return JSON.Parse(data);
}
private void LoadWeaponAttribute()
{
attribute = new Dictionary<int, Dictionary<int, WeaponAttributeData>>();
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<int, WeaponAttributeData>();
attribute[attributeData.Arms][attributeData.Level] = attributeData;
}
}
}
public WeaponAttributeData attributeData(int id,int level)
{
return attribute[id][level];
}
}