//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: Wednesday, February 13, 2019
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Threading;
|
using System;
|
using UnityEngine;
|
|
public partial class FaceConfig
|
{
|
|
public readonly string name;
|
public readonly int frameCnt;
|
public readonly int speed;
|
|
public FaceConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
name = tables[0];
|
|
int.TryParse(tables[1],out frameCnt);
|
|
int.TryParse(tables[2],out speed);
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<int, FaceConfig> configs = new Dictionary<int, FaceConfig>();
|
public static FaceConfig Get(int id)
|
{
|
if (!inited)
|
{
|
Debug.Log("FaceConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
FaceConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new FaceConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static bool Has(int id)
|
{
|
return configs.ContainsKey(id) || rawDatas.ContainsKey(id);
|
}
|
|
public static bool inited { get; private set; }
|
protected static Dictionary<int, string> rawDatas = null;
|
public static void Init(bool sync=false)
|
{
|
inited = false;
|
var path = string.Empty;
|
if (AssetSource.refdataFromEditor)
|
{
|
path = ResourcesPath.CONFIG_FODLER +"/Face.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/Face.txt");
|
}
|
|
if (sync)
|
{
|
var lines = File.ReadAllLines(path);
|
rawDatas = new Dictionary<int, string>(lines.Length - 3);
|
for (int i = 3; i < lines.Length; i++)
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
var idString = line.Substring(0, index);
|
var id = int.Parse(idString);
|
|
rawDatas[id] = line;
|
}
|
inited = true;
|
}
|
else
|
{
|
ThreadPool.QueueUserWorkItem((object _object) =>
|
{
|
var lines = File.ReadAllLines(path);
|
rawDatas = new Dictionary<int, string>(lines.Length - 3);
|
for (int i = 3; i < lines.Length; i++)
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
var idString = line.Substring(0, index);
|
var id = int.Parse(idString);
|
|
rawDatas[id] = line;
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|