/// <summary> /// 从旧的路径list中移除未改变的路径 删除剩余的文件; /// </summary> /// <param name="cfg"></param> private static void DeleteNotChangePath(ConfigGroupsSettings cfg) { for (int i = 0; i < cfg.xmlGroups.Length; i++) { if (mOldFilePath.Contains(cfg.xmlGroups[i].group)) { mOldFilePath.Remove(cfg.xmlGroups[i].group); } } for (int i = 0; i < cfg.xmlLevelGroups.Length; i++) { if (mOldFilePath.Contains(cfg.xmlLevelGroups[i].group)) { mOldFilePath.Remove(cfg.xmlLevelGroups[i].group); } } for (int i = 0; i < cfg.xmlSheetGroups.Length; i++) { if (mOldFilePath.Contains(cfg.xmlSheetGroups[i].group)) { mOldFilePath.Remove(cfg.xmlSheetGroups[i].group); } } DeleteFile(); }
public static void SerializerConfig() { GameConfigData gameConfigData = GameConfigDataBase.GetInstance().GetGameConfigData(); if (gameConfigData == null) { Debug.Log("gameConfigData is null"); return; } string detailGameConfigPath = string.Format("{0}/../conf/{1}", Application.dataPath, gameConfigData.detailGameConfigPath); string datPath = string.Format("{0}/../conf/{1}", Application.dataPath, gameConfigData.datPath); GetTargetDirAllFilePath(datPath); FunPlus.Util.CheckXML.GetInstance().LoadIgnoreFile(); GameConfigGroups gameXmlGroups; GameConfigGroups gameXmlSheetGroups; //GameConfigGroups gameXmlLevelGroups; //GameConfigDataBase.GetInstance().TryGetGroups(out gameXmlGroups, out gameXmlSheetGroups, out gameXmlLevelGroups); GameConfigDataBase.GetInstance().TryGetGroups(out gameXmlGroups, out gameXmlSheetGroups); GetAllFileByXmlGroup(gameXmlGroups); SerializeAllXml(mXmlGroups); //GetAllFileByXmlLevelGroup(gameXmlLevelGroups); //SerializeAllXml(mXmlLevelGroups); GetAllFileBySheetGroup(gameXmlSheetGroups); SerializeAllXmlSheet(mXmlSheetGroups); ConfigGroupsSettings conf = new ConfigGroupsSettings(); conf.xmlGroups = mXmlGroups.ToArray(); conf.xmlSheetGroups = mXmlSheetGroups.ToArray(); conf.xmlLevelGroups = mXmlLevelGroups.ToArray(); //删除这次生成之外的文件 DeleteNotChangePath(conf); ReplaceRelativePath(ref conf); GameConfigDataBase.GetInstance().DetailPathWriteToFile <ConfigGroupsSettings>(conf, detailGameConfigPath); }
// 替换为相对路径; private static void ReplaceRelativePath(ref ConfigGroupsSettings conf) { if (conf == null) { return; } string rootPath = Application.dataPath + "/../"; if (conf.xmlGroups != null) { for (int i = 0; i < conf.xmlGroups.Length; i++) { XmlGroupSettings xmlGroupSettings = conf.xmlGroups[i]; if (xmlGroupSettings == null) { continue; } xmlGroupSettings.group = xmlGroupSettings.group.Replace(rootPath, ""); if (xmlGroupSettings.xmlFiles == null) { continue; } for (int j = 0, jmax = xmlGroupSettings.xmlFiles.Length; j < jmax; j++) { XmlGroupSettings.XmlData xmlData = xmlGroupSettings.xmlFiles[j]; if (xmlData == null) { continue; } xmlData.path = xmlData.path.Replace(rootPath, ""); } } } if (conf.xmlSheetGroups != null) { for (int i = 0; i < conf.xmlSheetGroups.Length; i++) { XmlSheetGroupSettings xmlSheetGroupSettings = conf.xmlSheetGroups[i]; if (xmlSheetGroupSettings == null) { continue; } xmlSheetGroupSettings.group = xmlSheetGroupSettings.group.Replace(rootPath, ""); if (xmlSheetGroupSettings.sheetFiles == null) { continue; } for (int j = 0, jmax = xmlSheetGroupSettings.sheetFiles.Length; j < jmax; j++) { XmlSheetGroupSettings.XmlSheetData xmlSheetData = xmlSheetGroupSettings.sheetFiles[j]; if (xmlSheetData == null || xmlSheetData.files == null) { continue; } for (int k = 0, kmax = xmlSheetData.files.Length; k < kmax; k++) { XmlSheetGroupSettings.XmlSheetFile xmlSheetFile = xmlSheetData.files[k]; if (xmlSheetFile == null) { continue; } xmlSheetFile.filePath = xmlSheetFile.filePath.Replace(rootPath, ""); } } } } }