//--------------------------------------------------------
|
// [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 FashionDressConfig
|
{
|
|
public readonly int CoatID;
|
public readonly string name;
|
public readonly int type;
|
public readonly int FashionSuitType;
|
public readonly int quality;
|
public readonly string getWay;
|
public readonly int[] EquipItemID;
|
public readonly int UnlockItemID;
|
public readonly int MaxLV;
|
public readonly int[] CostItemCnt;
|
public readonly string StarAttr;
|
|
public FashionDressConfig()
|
{
|
}
|
|
public FashionDressConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
int.TryParse(tables[0],out CoatID);
|
|
name = tables[1];
|
|
int.TryParse(tables[2],out type);
|
|
int.TryParse(tables[3],out FashionSuitType);
|
|
int.TryParse(tables[4],out quality);
|
|
getWay = tables[5];
|
|
if (tables[6].Contains("["))
|
{
|
EquipItemID = JsonMapper.ToObject<int[]>(tables[6]);
|
}
|
else
|
{
|
string[] EquipItemIDStringArray = tables[6].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
EquipItemID = new int[EquipItemIDStringArray.Length];
|
for (int i=0;i<EquipItemIDStringArray.Length;i++)
|
{
|
int.TryParse(EquipItemIDStringArray[i],out EquipItemID[i]);
|
}
|
}
|
|
int.TryParse(tables[7],out UnlockItemID);
|
|
int.TryParse(tables[8],out MaxLV);
|
|
if (tables[9].Contains("["))
|
{
|
CostItemCnt = JsonMapper.ToObject<int[]>(tables[9]);
|
}
|
else
|
{
|
string[] CostItemCntStringArray = tables[9].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
CostItemCnt = new int[CostItemCntStringArray.Length];
|
for (int i=0;i<CostItemCntStringArray.Length;i++)
|
{
|
int.TryParse(CostItemCntStringArray[i],out CostItemCnt[i]);
|
}
|
}
|
|
StarAttr = tables[10];
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, FashionDressConfig> configs = new Dictionary<string, FashionDressConfig>();
|
public static FashionDressConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.LogError("FashionDressConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
FashionDressConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new FashionDressConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static FashionDressConfig 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<FashionDressConfig> GetValues()
|
{
|
var values = new List<FashionDressConfig>();
|
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 +"/FashionDress.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/FashionDress.txt");
|
}
|
|
configs.Clear();
|
var tempConfig = new FashionDressConfig();
|
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 FashionDressConfig(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 FashionDressConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|
|
|
|
|