/// <summary> /// 初始化配置 /// </summary> /// <typeparam name="TblClass"></typeparam> /// <typeparam name="CfgClass"></typeparam> private void InitCfg <TblClass, CfgClass>() where CfgClass : class, new() { CfgClass cfg = new CfgClass(); Type type = cfg.GetType(); MethodInfo info = type.GetMethod("Init"); if (info != null) { Dictionary <int, BaseConfig> config = info.Invoke(cfg, null) as Dictionary <int, BaseConfig>; configPool.Add(typeof(TblClass), config); } else { Log.Error("Table Is Not Exist Init Method"); } cfg = null; }
/// <summary> /// 读取Json数据 /// </summary> public static List <ChessCfg> ReadJson() { if (cfg == null) { TextAsset textAsset = new TextAsset(); textAsset = Resources.Load("Json/t_ChessConfig") as TextAsset; string txt = textAsset.text; if (txt != string.Empty) { CfgClass item = JsonUtility.FromJson <CfgClass>(txt); //反序列化后存储到类或结构体 cfg = item.Attributes; //获取类的对象拥有的属性列表 } } return(cfg); }