//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: Friday, October 23, 2020
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System;
|
using UnityEngine;
|
|
|
namespace StartAot
|
{
|
public class InitialFunctionConfig
|
{
|
|
public readonly string KEY;
|
public readonly string Numerical1;
|
public readonly string Numerical2;
|
public readonly string Numerical3;
|
public readonly string Numerical4;
|
public readonly string Numerical5;
|
|
public InitialFunctionConfig()
|
{
|
}
|
|
public InitialFunctionConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
KEY = tables[0];
|
|
Numerical1 = tables[1];
|
|
Numerical2 = tables[2];
|
|
Numerical3 = tables[3];
|
|
Numerical4 = tables[4];
|
|
Numerical5 = tables[5];
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, InitialFunctionConfig> configs = new Dictionary<string, InitialFunctionConfig>();
|
public static InitialFunctionConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.LogError("InitialFunctionConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
InitialFunctionConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new InitialFunctionConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static InitialFunctionConfig 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<InitialFunctionConfig> GetValues()
|
{
|
var values = new List<InitialFunctionConfig>();
|
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(string content)
|
{
|
inited = false;
|
configs.Clear();
|
using (StringReader reader = new StringReader(content))
|
{
|
string line;
|
int lineIndex = 0;
|
while ((line = reader.ReadLine()) != null)
|
{
|
lineIndex++;
|
if (lineIndex <= 3)
|
{
|
continue;
|
}
|
try
|
{
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
rawDatas[id] = line;
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
}
|
inited = true;
|
Debug.Log("InitialFunctionConfig Init Finished line = " + rawDatas.Count);
|
}
|
|
}
|
|
}
|
|
|