//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: Thursday, February 14, 2019
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Threading;
|
using System;
|
using UnityEngine;
|
|
[XLua.LuaCallCSharp]
|
public partial class SuccessConfig
|
{
|
|
public readonly int ID;
|
public readonly int Type;
|
public readonly int Group;
|
public readonly int NeedCnt;
|
public readonly int[] Condition;
|
public readonly string Condition2;
|
public readonly int Condition3;
|
public readonly string AwardItemList;
|
public readonly string Money;
|
public readonly int Exp;
|
public readonly int[] AwardAttribute;
|
public readonly int RedPacketID;
|
public readonly int MagicWeaponID;
|
public readonly string MagicWeaponExp;
|
public readonly string Describe;
|
public readonly int NeedGoto;
|
public readonly int Jump;
|
public readonly int ReOrder;
|
public readonly int RealmPracticeID;
|
|
public SuccessConfig()
|
{
|
}
|
|
public SuccessConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
int.TryParse(tables[0],out ID);
|
|
int.TryParse(tables[1],out Type);
|
|
int.TryParse(tables[2],out Group);
|
|
int.TryParse(tables[3],out NeedCnt);
|
|
string[] ConditionStringArray = tables[4].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
Condition = new int[ConditionStringArray.Length];
|
for (int i=0;i<ConditionStringArray.Length;i++)
|
{
|
int.TryParse(ConditionStringArray[i],out Condition[i]);
|
}
|
|
Condition2 = tables[5];
|
|
int.TryParse(tables[6],out Condition3);
|
|
AwardItemList = tables[7];
|
|
Money = tables[8];
|
|
int.TryParse(tables[9],out Exp);
|
|
string[] AwardAttributeStringArray = tables[10].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
AwardAttribute = new int[AwardAttributeStringArray.Length];
|
for (int i=0;i<AwardAttributeStringArray.Length;i++)
|
{
|
int.TryParse(AwardAttributeStringArray[i],out AwardAttribute[i]);
|
}
|
|
int.TryParse(tables[11],out RedPacketID);
|
|
int.TryParse(tables[12],out MagicWeaponID);
|
|
MagicWeaponExp = tables[13];
|
|
Describe = tables[14];
|
|
int.TryParse(tables[15],out NeedGoto);
|
|
int.TryParse(tables[16],out Jump);
|
|
int.TryParse(tables[17],out ReOrder);
|
|
int.TryParse(tables[18],out RealmPracticeID);
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, SuccessConfig> configs = new Dictionary<string, SuccessConfig>();
|
public static SuccessConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.Log("SuccessConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
SuccessConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new SuccessConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static SuccessConfig 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<SuccessConfig> GetValues()
|
{
|
var values = new List<SuccessConfig>();
|
values.AddRange(configs.Values);
|
|
var keys = new List<string>(rawDatas.Keys);
|
foreach (var key in keys)
|
{
|
values.Add(Get(key));
|
}
|
|
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 +"/Success.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/Success.txt");
|
}
|
|
var tempConfig = new SuccessConfig();
|
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 SuccessConfig(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 SuccessConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|
|
|
|
|