mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update ResConfigUtil.cs
This commit is contained in:
@@ -12,6 +12,7 @@ namespace TEngine.Runtime
|
|||||||
/// <param name="val"></param>
|
/// <param name="val"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public delegate bool FilterResBin<TType>(TType val);
|
public delegate bool FilterResBin<TType>(TType val);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 计算拼接Key
|
/// 计算拼接Key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,19 +22,21 @@ namespace TEngine.Runtime
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public delegate TKey ConvertDictionaryKey<TKey, TValue>(TValue val);
|
public delegate TKey ConvertDictionaryKey<TKey, TValue>(TValue val);
|
||||||
|
|
||||||
public class ResConfigUtil
|
public class ResConfigUtil
|
||||||
{
|
{
|
||||||
private static StringBuilder m_strBuilder = new StringBuilder();
|
private static StringBuilder _mStrBuilder = new StringBuilder();
|
||||||
private static readonly string m_split = "_";
|
private static readonly string MSplit = "_";
|
||||||
|
|
||||||
#region 读取接口
|
#region 读取接口
|
||||||
|
|
||||||
public static List<T> ReadConfigListRes<T>(string fileName = "")
|
public static List<T> ReadConfigListRes<T>(string fileName = "")
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
fileName = typeof(T).Name;
|
fileName = typeof(T).Name;
|
||||||
}
|
}
|
||||||
string resPath = string.Format("Config/{0}.json",fileName);
|
|
||||||
|
string resPath = string.Format("Config/{0}.json", fileName);
|
||||||
TextAsset jsonStr = TResources.Load<TextAsset>(resPath);
|
TextAsset jsonStr = TResources.Load<TextAsset>(resPath);
|
||||||
if (jsonStr == null)
|
if (jsonStr == null)
|
||||||
{
|
{
|
||||||
@@ -47,7 +50,8 @@ namespace TEngine.Runtime
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> ReadResBinDict<K,T>(Dictionary<K, T> dic,ConvertDictionaryKey<K,T> convKey ,string fileName = "")
|
public static List<T> ReadResBinDict<K, T>(Dictionary<K, T> dic, ConvertDictionaryKey<K, T> convKey,
|
||||||
|
string fileName = "")
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
@@ -66,7 +70,7 @@ namespace TEngine.Runtime
|
|||||||
|
|
||||||
var etr = jsonData.GetEnumerator();
|
var etr = jsonData.GetEnumerator();
|
||||||
|
|
||||||
if(dic == null)
|
if (dic == null)
|
||||||
{
|
{
|
||||||
dic = new Dictionary<K, T>();
|
dic = new Dictionary<K, T>();
|
||||||
}
|
}
|
||||||
@@ -81,8 +85,10 @@ namespace TEngine.Runtime
|
|||||||
{
|
{
|
||||||
if (dic.ContainsKey(key))
|
if (dic.ContainsKey(key))
|
||||||
{
|
{
|
||||||
TLogger.LogError("Config {0} Load Error, Repeat config {1}",typeof(T).ToString(),key.ToString());
|
TLogger.LogError("Config {0} Load Error, Repeat config {1}", typeof(T).ToString(),
|
||||||
|
key.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
dic.Add(key, etr.Current);
|
dic.Add(key, etr.Current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +98,8 @@ namespace TEngine.Runtime
|
|||||||
return jsonData;
|
return jsonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> ReadResBinDict<K, T>(Dictionary<K, List<T>> dict, ConvertDictionaryKey<K, T> convKey, string fileName = "")
|
public static List<T> ReadResBinDict<K, T>(Dictionary<K, List<T>> dict, ConvertDictionaryKey<K, T> convKey,
|
||||||
|
string fileName = "")
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
@@ -118,6 +125,7 @@ namespace TEngine.Runtime
|
|||||||
{
|
{
|
||||||
dict.Clear();
|
dict.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (etr.MoveNext())
|
while (etr.MoveNext())
|
||||||
{
|
{
|
||||||
var data = etr.Current;
|
var data = etr.Current;
|
||||||
@@ -128,12 +136,15 @@ namespace TEngine.Runtime
|
|||||||
listItem = new List<T>();
|
listItem = new List<T>();
|
||||||
dict.Add(key, listItem);
|
dict.Add(key, listItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
listItem.Add(data);
|
listItem.Add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
etr.Dispose();
|
etr.Dispose();
|
||||||
|
|
||||||
return jsonData;
|
return jsonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static UInt64 Make64Key(uint key1, uint key2)
|
public static UInt64 Make64Key(uint key1, uint key2)
|
||||||
@@ -143,31 +154,31 @@ namespace TEngine.Runtime
|
|||||||
|
|
||||||
public static string MakeStringKey(uint key1, uint key2, uint key3)
|
public static string MakeStringKey(uint key1, uint key2, uint key3)
|
||||||
{
|
{
|
||||||
m_strBuilder.Length = 0;
|
_mStrBuilder.Length = 0;
|
||||||
m_strBuilder.Append(key1);
|
_mStrBuilder.Append(key1);
|
||||||
m_strBuilder.Append(m_split);
|
_mStrBuilder.Append(MSplit);
|
||||||
m_strBuilder.Append(key2);
|
_mStrBuilder.Append(key2);
|
||||||
m_strBuilder.Append(m_split);
|
_mStrBuilder.Append(MSplit);
|
||||||
m_strBuilder.Append(key3);
|
_mStrBuilder.Append(key3);
|
||||||
return m_strBuilder.ToString();
|
return _mStrBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string MakeStringKey(string key1, uint key2)
|
public static string MakeStringKey(string key1, uint key2)
|
||||||
{
|
{
|
||||||
m_strBuilder.Length = 0;
|
_mStrBuilder.Length = 0;
|
||||||
m_strBuilder.Append(key1);
|
_mStrBuilder.Append(key1);
|
||||||
m_strBuilder.Append(m_split);
|
_mStrBuilder.Append(MSplit);
|
||||||
m_strBuilder.Append(key2);
|
_mStrBuilder.Append(key2);
|
||||||
return m_strBuilder.ToString();
|
return _mStrBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string MakeStringKey(string key1, string key2)
|
public static string MakeStringKey(string key1, string key2)
|
||||||
{
|
{
|
||||||
m_strBuilder.Length = 0;
|
_mStrBuilder.Length = 0;
|
||||||
m_strBuilder.Append(key1);
|
_mStrBuilder.Append(key1);
|
||||||
m_strBuilder.Append(m_split);
|
_mStrBuilder.Append(MSplit);
|
||||||
m_strBuilder.Append(key2);
|
_mStrBuilder.Append(key2);
|
||||||
return m_strBuilder.ToString();
|
return _mStrBuilder.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user