/// <summary> /// 导入明文配置数据(泛型) /// </summary> /// <param name="strInfo"></param> public void ImportStrInfo <T>(string strInfo, ConfigDataCallBack callBack = null) where T : Config { try { ImportStrInfo(typeof(T), strInfo, null, callBack); } catch (Exception ex) { Debug.Log("导入配置表出错:" + "类型:" + typeof(T)); throw; } }
public void ImportStrInfo(Type type, string strInfo, Type derivedType = null, ConfigDataCallBack callBack = null) { if (!IsConfigClass(type)) { Debug.Log("导入的配置类型不符合要求,type name = " + type.Name); return; } lock (_iLock) { if (!_configs.ContainsKey(type)) { _configs.Add(type, new Dictionary <long, Config>()); } if (_sourceData.ContainsKey(type) && derivedType == null) { return; } string[] lineArr = strInfo.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //导入文件字段数据 string[][] tempArr2 = new string[3][]; for (int i = 0; i < 3; i++) { tempArr2[i] = lineArr[i].Split('\t'); } if (derivedType != null) { //检查数据格式 if (!CheckConfig(derivedType, tempArr2[2], tempArr2[0])) { return; } if (!_dicFileFieldInfo.ContainsKey(derivedType.Name)) { _dicFileFieldInfo.Add(derivedType.Name, tempArr2); } } else { //检查数据格式 if (!CheckConfig(type, tempArr2[2], tempArr2[0])) { return; } if (!_dicFileFieldInfo.ContainsKey(type.Name)) { _dicFileFieldInfo.Add(type.Name, tempArr2); } } //导入文件配置数据 if (derivedType != null && _sourceData.ContainsKey(type)) { for (int i = 3; i < lineArr.Length; i++) { if (lineArr[i].Replace("\t", "") == "" || lineArr[i].Replace("\fieldType", "") == null) { continue; } string str = lineArr[i].Contains("\t") ? lineArr[i].Substring(0, lineArr[i].IndexOf("\t")) : lineArr[i]; long n; if (long.TryParse(str, out n)) { n = long.Parse(str); FileLineInfo tempfi; tempfi.LineData = lineArr[i].Split('\t'); for (int j = 0; j < tempfi.LineData.Length; j++) { if (callBack != null) { callBack(i, _dicFileFieldInfo[derivedType.Name][2][j], ref tempfi.LineData[j]); } } tempfi.DerivedType = derivedType; if (!_sourceData[type].ContainsKey(n)) { _sourceData[type].Add(n, tempfi); } else { Debug.Log("配置表" + derivedType.Name + "导入配置数据id错误(第" + (i + 1) + "行 , 第1列):数据id(" + str + ")已导入,导入此配置数据失败!" + "重复来源:" + _sourceData[type][n].DerivedType.Name); } } else { Debug.Log("配置表" + type.Name + "导入配置数据id错误(第" + (i + 1) + "行 , 第1列) : 数据id号(" + str + ")的格式不符合要求,导入此配置数据失败!"); } } } else { Dictionary <long, FileLineInfo> tempDic = new Dictionary <long, FileLineInfo>(); for (int i = 3; i < lineArr.Length; i++) { if (lineArr[i].Replace("\t", "") == "" || lineArr[i].Replace("\fieldType", "") == null) { continue; } string str = lineArr[i].Contains("\t") ? lineArr[i].Substring(0, lineArr[i].IndexOf("\t")) : lineArr[i]; if (str.EndsWith("@")) { str = str.Remove(str.Length - 1); } long n; if (str.StartsWith("#")) { continue; } if (str == null || str == "") { Debug.Log("配置表" + type.Name + "导入配置数据id错误(第" + (i + 1) + "行 , 第1列) : 数据id号(" + str + ")的格式不符合要求,导入此配置数据失败!"); continue; } if (long.TryParse(str, out n)) { n = long.Parse(str); FileLineInfo tempfi; tempfi.LineData = lineArr[i].Split('\t'); for (int j = 0; j < tempfi.LineData.Length; j++) { if (callBack != null) { callBack(i, _dicFileFieldInfo[type.Name][2][j], ref tempfi.LineData[j]); } } tempfi.DerivedType = derivedType; if (!tempDic.ContainsKey(n)) { tempDic.Add(n, tempfi); } else { Debug.Log("配置表" + type.Name + "导入配置数据id错误(第" + (i + 1) + "行 , 第1列) : 数据id(" + str + ")已导入,导入此配置数据失败!"); } } else { Debug.Log("配置表" + type.Name + "导入配置数据id错误(第" + (i + 1) + "行 , 第1列) : 数据id号(" + str + ")的格式不符合要求,导入此配置数据失败!"); } } _sourceData.Add(type, tempDic); } } }