//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: 2024年5月17日
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Threading;
|
using System;
|
using UnityEngine;
|
using LitJson;
|
|
public partial class EquipShenAttrConfig
|
{
|
|
public readonly int ID;
|
public readonly int[] ShenAttrID;
|
public readonly int[] ShenAttrValue;
|
public readonly int[] XianAttrID;
|
public readonly int[] XianAttrValue;
|
public readonly int[] JiAttrID;
|
public readonly int[] JiAttrValue;
|
public readonly int[] LegendAttrID;
|
public readonly int[] LegendAttrValue;
|
|
public EquipShenAttrConfig()
|
{
|
}
|
|
public EquipShenAttrConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
int.TryParse(tables[0],out ID);
|
|
if (tables[1].Contains("["))
|
{
|
ShenAttrID = JsonMapper.ToObject<int[]>(tables[1]);
|
}
|
else
|
{
|
string[] ShenAttrIDStringArray = tables[1].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
ShenAttrID = new int[ShenAttrIDStringArray.Length];
|
for (int i=0;i<ShenAttrIDStringArray.Length;i++)
|
{
|
int.TryParse(ShenAttrIDStringArray[i],out ShenAttrID[i]);
|
}
|
}
|
|
if (tables[2].Contains("["))
|
{
|
ShenAttrValue = JsonMapper.ToObject<int[]>(tables[2]);
|
}
|
else
|
{
|
string[] ShenAttrValueStringArray = tables[2].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
ShenAttrValue = new int[ShenAttrValueStringArray.Length];
|
for (int i=0;i<ShenAttrValueStringArray.Length;i++)
|
{
|
int.TryParse(ShenAttrValueStringArray[i],out ShenAttrValue[i]);
|
}
|
}
|
|
if (tables[3].Contains("["))
|
{
|
XianAttrID = JsonMapper.ToObject<int[]>(tables[3]);
|
}
|
else
|
{
|
string[] XianAttrIDStringArray = tables[3].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
XianAttrID = new int[XianAttrIDStringArray.Length];
|
for (int i=0;i<XianAttrIDStringArray.Length;i++)
|
{
|
int.TryParse(XianAttrIDStringArray[i],out XianAttrID[i]);
|
}
|
}
|
|
if (tables[4].Contains("["))
|
{
|
XianAttrValue = JsonMapper.ToObject<int[]>(tables[4]);
|
}
|
else
|
{
|
string[] XianAttrValueStringArray = tables[4].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
XianAttrValue = new int[XianAttrValueStringArray.Length];
|
for (int i=0;i<XianAttrValueStringArray.Length;i++)
|
{
|
int.TryParse(XianAttrValueStringArray[i],out XianAttrValue[i]);
|
}
|
}
|
|
if (tables[5].Contains("["))
|
{
|
JiAttrID = JsonMapper.ToObject<int[]>(tables[5]);
|
}
|
else
|
{
|
string[] JiAttrIDStringArray = tables[5].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
JiAttrID = new int[JiAttrIDStringArray.Length];
|
for (int i=0;i<JiAttrIDStringArray.Length;i++)
|
{
|
int.TryParse(JiAttrIDStringArray[i],out JiAttrID[i]);
|
}
|
}
|
|
if (tables[6].Contains("["))
|
{
|
JiAttrValue = JsonMapper.ToObject<int[]>(tables[6]);
|
}
|
else
|
{
|
string[] JiAttrValueStringArray = tables[6].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
JiAttrValue = new int[JiAttrValueStringArray.Length];
|
for (int i=0;i<JiAttrValueStringArray.Length;i++)
|
{
|
int.TryParse(JiAttrValueStringArray[i],out JiAttrValue[i]);
|
}
|
}
|
|
if (tables[7].Contains("["))
|
{
|
LegendAttrID = JsonMapper.ToObject<int[]>(tables[7]);
|
}
|
else
|
{
|
string[] LegendAttrIDStringArray = tables[7].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
LegendAttrID = new int[LegendAttrIDStringArray.Length];
|
for (int i=0;i<LegendAttrIDStringArray.Length;i++)
|
{
|
int.TryParse(LegendAttrIDStringArray[i],out LegendAttrID[i]);
|
}
|
}
|
|
if (tables[8].Contains("["))
|
{
|
LegendAttrValue = JsonMapper.ToObject<int[]>(tables[8]);
|
}
|
else
|
{
|
string[] LegendAttrValueStringArray = tables[8].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
LegendAttrValue = new int[LegendAttrValueStringArray.Length];
|
for (int i=0;i<LegendAttrValueStringArray.Length;i++)
|
{
|
int.TryParse(LegendAttrValueStringArray[i],out LegendAttrValue[i]);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, EquipShenAttrConfig> configs = new Dictionary<string, EquipShenAttrConfig>();
|
public static EquipShenAttrConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.LogError("EquipShenAttrConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
EquipShenAttrConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new EquipShenAttrConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static EquipShenAttrConfig Get(int id)
|
{
|
return Get(id.ToString());
|
}
|
|
public static List<string> GetKeys()
|
{
|
var keys = new List<string>();
|
keys.AddRange(configs.Keys);
|
keys.AddRange(rawDatas.Keys);
|
return keys;
|
}
|
|
public static List<EquipShenAttrConfig> GetValues()
|
{
|
var values = new List<EquipShenAttrConfig>();
|
values.AddRange(configs.Values);
|
|
var keys = new List<string>(rawDatas.Keys);
|
for (int i = 0; i < keys.Count; i++)
|
{
|
values.Add(Get(keys[i]));
|
}
|
|
return values;
|
}
|
|
public static bool Has(string id)
|
{
|
return configs.ContainsKey(id) || rawDatas.ContainsKey(id);
|
}
|
|
public static bool Has(int id)
|
{
|
return Has(id.ToString());
|
}
|
|
public static bool inited { get; private set; }
|
protected static Dictionary<string, string> rawDatas = new Dictionary<string, string>();
|
public static void Init(bool sync=false)
|
{
|
inited = false;
|
var path = string.Empty;
|
if (AssetSource.refdataFromEditor)
|
{
|
path = ResourcesPath.CONFIG_FODLER +"/EquipShenAttr.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/EquipShenAttr.txt");
|
}
|
|
configs.Clear();
|
var tempConfig = new EquipShenAttrConfig();
|
var preParse = tempConfig is IConfigPostProcess;
|
|
if (sync)
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new EquipShenAttrConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
inited = true;
|
}
|
else
|
{
|
ThreadPool.QueueUserWorkItem((object _object) =>
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new EquipShenAttrConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|
|
|
|
|