public static CBaseInfo LoadFromTab(Type type, CTabFile tabFile, int row) { CBaseInfo newT = Activator.CreateInstance(type) as CBaseInfo; LoadFromTab(type, ref newT, tabFile, row); return(newT); }
static void CheckConfigFile() { if (!File.Exists(ConfFilePath)) { CTabFile confFile = new CTabFile(); confFile.NewRow(); confFile.NewColumn("Key"); confFile.NewColumn("Value"); confFile.NewColumn("Comment"); foreach (string[] strArr in DefaultConfigFileContent) { int row = confFile.NewRow(); confFile.SetValue<string>(row, "Key", strArr[0]); confFile.SetValue<string>(row, "Value", strArr[1]); confFile.SetValue<string>(row, "Comment", strArr[2]); } confFile.Save(ConfFilePath); CBase.Log("新建CosmosEngine配置文件: {0}", ConfFilePath); AssetDatabase.Refresh(); } ConfFile = CTabFile.LoadFromFile(ConfFilePath); }
static void CheckConfigFile() { if (!File.Exists(ConfFilePath)) { CTabFile confFile = new CTabFile(); confFile.NewColumn("Key"); confFile.NewColumn("Value"); confFile.NewColumn("Comment"); foreach (string[] strArr in DefaultConfigFileContent) { int row = confFile.NewRow(); confFile.SetValue <string>(row, "Key", strArr[0]); confFile.SetValue <string>(row, "Value", strArr[1]); confFile.SetValue <string>(row, "Comment", strArr[2]); } confFile.Save(ConfFilePath); CDebug.Log("新建CosmosEngine配置文件: {0}", ConfFilePath); AssetDatabase.Refresh(); } ConfFile = CTabFile.LoadFromFile(ConfFilePath); }
public static void SetupHistory(bool rebuild) { IsCheckMd5 = true; BuildVersion.Clear(); if (!rebuild) { string verFile = GetBuildVersionTab(); //MakeSureExportPath(VerCtrlInfo.VerFile, EditorUserBuildSettings.activeBuildTarget); CTabFile tabFile; if (File.Exists(verFile)) { tabFile = CTabFile.LoadFromFile(verFile); foreach (CTabFile.RowInterator row in tabFile) { BuildVersion[row.GetString("AssetPath")] = new BuildRecord( row.GetString("AssetMD5"), row.GetString("AssetDateTime"), row.GetInteger("ChangeCount")); } } } else { } }
// 直接从字符串分析 public static CTabFile LoadFromString(string content) { CTabFile tabFile = new CTabFile(); tabFile.ParseString(content); return(tabFile); }
// 直接从文件, 传入完整目录,跟通过资源管理器自动生成完整目录不一样,给art库用的 public static CTabFile LoadFromFile(string fileFullPath) { CTabFile tabFile = new CTabFile(); if (tabFile.LoadByIO(fileFullPath)) { return(tabFile); } else { return(null); } }
/// <summary> /// 真正进行读取 /// </summary> /// <param name="type"></param> /// <param name="contents"></param> private void DoLoadTab(Type type, IEnumerable <string> contents) { CDebug.Assert(typeof(CBaseInfo).IsAssignableFrom(type)); foreach (string content in contents) { using (CTabFile tabFile = CTabFile.LoadFromString(content)) { Dictionary <string, CBaseInfo> dict; if (!SettingInfos.TryGetValue(type, out dict)) // 如果没有才添加 { dict = new Dictionary <string, CBaseInfo>(); } const int rowStart = 1; for (int row = rowStart; row <= tabFile.GetHeight(); row++) { // 先读取ID, 获取是否之前已经读取过配置, // 如果已经读取过,那么获取原配置对象,并重新赋值 (因为游戏中其它地方已经存在它的引用了,直接替换内存泄露) string id = tabFile.GetString(row, "Id"); // 获取ID是否存在, 如果已经存在,那么替换其属性,不new一个 CBaseInfo existOne; if (dict.TryGetValue(id, out existOne)) { if (FoundDuplicatedIdEvent != null) { FoundDuplicatedIdEvent(type, row, id); } CBaseInfo existInfo = existOne; existInfo.ReadFromTab(type, ref existInfo, tabFile, row); // 修改原对象,不new existInfo.CustomReadLine(tabFile, row); (existInfo as CBaseInfo).Parse(); } else { CBaseInfo pInfo = CBaseInfo.NewFromTab(type, tabFile, row); pInfo.CustomReadLine(tabFile, row); pInfo.Parse(); dict[pInfo.Id] = pInfo; // 不存在,直接new } } SettingInfos[type] = dict; } } }
/// <summary> /// Ensure the CEngineConfig file loaded. /// </summary> static void EnsureConfigTab() { if (ConfigMap == null) { TextAsset textAsset; textAsset = Resources.Load <TextAsset>("CEngineConfig"); CBase.Assert(textAsset); CTabFile configTab = CTabFile.LoadFromString(textAsset.text); ConfigMap = new Dictionary <string, string>(); foreach (CTabFile.CTabRow row in configTab) { string key = row.GetString("Key"); string value = row.GetString("Value"); ConfigMap[key] = value; } } }
public static bool IsCheckMd5 = false; // 跟AssetServer关联~如果true,函数才有效 public static void WriteVersion() { string path = GetBuildVersionTab();// MakeSureExportPath(VerCtrlInfo.VerFile, EditorUserBuildSettings.activeBuildTarget); CTabFile tabFile = new CTabFile(); tabFile.NewColumn("AssetPath"); tabFile.NewColumn("AssetMD5"); tabFile.NewColumn("AssetDateTime"); tabFile.NewColumn("ChangeCount"); foreach (var node in BuildVersion) { int row = tabFile.NewRow(); tabFile.SetValue(row, "AssetPath", node.Key); tabFile.SetValue(row, "AssetMD5", node.Value.MD5); tabFile.SetValue(row, "AssetDateTime", node.Value.DateTime); tabFile.SetValue(row, "ChangeCount", node.Value.ChangeCount); } tabFile.Save(path); }
private void DoLoadTab <T>(string tabPath) where T : CBaseInfo { #if GAME_CLIENT //using (CTabReader tabFile = CTabReader.LoadFromString(tabPath, CSettingManager.Instance.LoadSetting(tabPath))) using (CTabFile tabFile = CTabFile.LoadFromString(CSettingManager.Instance.LoadSetting(tabPath))) #else // Editor Only string p1 = System.IO.Path.GetFullPath("Assets/" + CCosmosEngine.GetConfig("ProductRelPath") + "/") + tabPath; using (CTabFile tabFile = CTabFile.LoadFromString(System.IO.File.ReadAllText(p1))) #endif { int rowStart = 1; Dictionary <string, CBaseInfo> dict = new Dictionary <string, CBaseInfo>(); for (int i = rowStart; i < tabFile.GetHeight(); i++) { // 先读取ID, 获取是否之前已经读取过配置, // 如果已经读取过,那么获取原配置对象,并重新赋值 (因为游戏中其它地方已经存在它的引用了,直接替换内存泄露) string id = tabFile.GetString(i, "Id"); // 获取ID是否存在, 如果已经存在,那么替换其属性,不new一个 CBaseInfo existOne; if (dict.TryGetValue(id, out existOne)) { CBaseInfo existT = existOne; CBaseInfo.LoadFromTab(typeof(T), ref existT, tabFile, i); // 修改原对象,不new (existT as CBaseInfo).Parse(); } else { T pInfo = CBaseInfo.LoadFromTab(typeof(T), tabFile, i) as T; pInfo.Parse(); dict[pInfo.Id] = pInfo; // 不存在,直接new } } SettingInfos[typeof(T)] = dict; } }
internal RowInterator(CTabFile tabFile) { TabFile = tabFile; }
internal CTabRow(CTabFile tabFile) { TabFile = tabFile; }
public static void LoadFromTab(Type type, ref CBaseInfo newT, CTabFile tabFile, int row) { CBase.Assert(typeof(CBaseInfo).IsAssignableFrom(type)); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo field in fields) { if (!tabFile.HasColumn(field.Name)) { CBase.LogError("表{0} 找不到表头{1}", type.Name, field.Name); continue; } object value; if (field.FieldType == typeof(int)) { value = tabFile.GetInteger(row, field.Name); } else if (field.FieldType == typeof(long)) { value = (long)tabFile.GetInteger(row, field.Name); } else if (field.FieldType == typeof(string)) { value = tabFile.GetString(row, field.Name); } else if (field.FieldType == typeof(float)) { value = tabFile.GetFloat(row, field.Name); } else if (field.FieldType == typeof(bool)) { value = tabFile.GetBool(row, field.Name); } else if (field.FieldType == typeof(double)) { value = tabFile.GetDouble(row, field.Name); } else if (field.FieldType == typeof(uint)) { value = tabFile.GetUInteger(row, field.Name); } else if (field.FieldType == typeof(List <string>)) { string sz = tabFile.GetString(row, field.Name); value = CTool.Split <string>(sz, '|'); } else if (field.FieldType == typeof(List <int>)) { List <int> retInt = new List <int>(); string szArr = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(szArr)) { string[] szIntArr = szArr.Split('|'); foreach (string szInt in szIntArr) { float parseFloat; float.TryParse(szInt, out parseFloat); int parseInt_ = (int)parseFloat; retInt.Add(parseInt_); } value = retInt; } else { value = new List <int>(); } } else if (field.FieldType == typeof(List <List <string> >)) { string sz = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(sz)) { var szOneList = new List <List <string> >(); string[] szArr = sz.Split('|'); foreach (string szOne in szArr) { string[] szOneArr = szOne.Split('-'); szOneList.Add(new List <string>(szOneArr)); } value = szOneList; } else { value = new List <List <string> >(); } } else if (field.FieldType == typeof(List <List <int> >)) { string sz = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(sz)) { var zsOneIntList = new List <List <int> >(); string[] szArr = sz.Split('|'); foreach (string szOne in szArr) { List <int> retInts = new List <int>(); string[] szOneArr = szOne.Split('-'); foreach (string szOneInt in szOneArr) { float parseFloat; float.TryParse(szOneInt, out parseFloat); int parseInt_ = (int)parseFloat; retInts.Add(parseInt_); } zsOneIntList.Add(retInts); } value = zsOneIntList; } else { value = new List <List <int> >(); } } else { CBase.LogWarning("未知类型: {0}", field.Name); value = null; } if (field.Name == "Id") // 如果是Id主键,确保数字成整数!不是浮点数 因为excel转tab可能转成浮点 { float fValue; if (float.TryParse((string)value, out fValue)) { try { value = ((int)fValue).ToString(); } catch { CBase.LogError("转型错误...{0}", value.ToString()); } } } field.SetValue(newT, value); } }