|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class ConfigBase<U, T> where T : ConfigBase<U, T>, new() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 是否访问过静态构造函数 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public static bool visit = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | static ConfigBase() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (isInit) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Dictionary<U, T> m_dic = new Dictionary<U, T>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Dictionary<U, T> dic | 
|---|
|  |  |  | { | 
|---|
|  |  |  | get | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  | return m_dic; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static T Get(U id) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (m_dic.ContainsKey(id)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return m_dic[id]; | 
|---|
|  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void ForceInit() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ConfigManager.Instance.LoadConfigByType(typeof(T)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // public static void ForceRelease() | 
|---|
|  |  |  | // { | 
|---|
|  |  |  | //     m_dic.Clear(); | 
|---|
|  |  |  | //     isInit = false; | 
|---|
|  |  |  | // } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static List<U> GetKeys() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  | List<U> result = new List<U>(); | 
|---|
|  |  |  | result.AddRange(m_dic.Keys); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static List<T> GetValues() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  | List<T> result = new List<T>(); | 
|---|
|  |  |  | result.AddRange(m_dic.Values); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static bool HasKey(U key) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LazyInit(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return m_dic.ContainsKey(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void Init(string[] lines) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | m_dic.Clear(); | 
|---|
|  |  |  | if (isInit) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int i = 3; i < lines.Length; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string line = lines[i]; | 
|---|
|  |  |  | var index = line.IndexOf("\t"); | 
|---|
|  |  |  | if (index == -1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | string line = lines[i]; | 
|---|
|  |  |  | var index = line.IndexOf("\t"); | 
|---|
|  |  |  | if (index == -1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string strKey = line.Substring(0, index); | 
|---|
|  |  |  | T config = new T(); | 
|---|
|  |  |  | U key = config.LoadKey(strKey); | 
|---|
|  |  |  | config.LoadConfig(line); | 
|---|
|  |  |  | config.OnConfigParseCompleted(); | 
|---|
|  |  |  | string strKey = line.Substring(0, index); | 
|---|
|  |  |  | T config = new T(); | 
|---|
|  |  |  | U key = config.LoadKey(strKey); | 
|---|
|  |  |  | config.LoadConfig(line); | 
|---|
|  |  |  | config.OnConfigParseCompleted(); | 
|---|
|  |  |  | #if UNITY_EDITOR | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | #endif | 
|---|
|  |  |  | m_dic.Add(key, config); | 
|---|
|  |  |  | m_dic.Add(key, config); | 
|---|
|  |  |  | #if UNITY_EDITOR | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (ArgumentException exception) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Debug.LogError(typeof(T).Name + " 重复的key " + key + " " + exception.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (ArgumentException exception) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Debug.LogError(typeof(T).Name + " 重复的key " + key + " " + exception.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endif | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | foreach (var cfg in m_dic.Values) | 
|---|
|  |  |  | { | 
|---|