public static int[][] ReadValueLocArray2(CsvSpreadSheet sheet, int index, string headerName) { int row = sheet.GetRecord(index).StartRow; int column = sheet.GetHeaderRecord(headerName).Index; int len = sheet.GetRecord(index).HeaderContentLength[column]; int[][] result = new int[len][]; for (int i = 0; i < len; i++) { result[i] = ParseCsvRecordLocArray(sheet.GetValue(i + row, column)); } return(result); }
public static int ReadValueCsvLoc(CsvSpreadSheet sheet, int index, string headerName) { int row = sheet.GetRecord(index).StartRow; int column = sheet.GetHeaderRecord(headerName).Index; if (string.IsNullOrEmpty(sheet.GetValue(row, column))) { return(0); } else { return(LocalizationCsvData.IdRecordValue[sheet.GetValue(row, column)]); } }
public static int[] ReadValueLocArrayLine(CsvSpreadSheet sheet, int index, string headerName) { int row = sheet.GetRecord(index).StartRow; int column = sheet.GetHeaderRecord(headerName).Index; var line = sheet.GetValue(row, column).Split(new Char[] { '|', '#' }); int[] result = new int[line.Length]; for (int i = 0; i < line.Length; i++) { if (string.IsNullOrEmpty(sheet.GetValue(row + i, column))) { result[i] = 0; } else { result[i] = LocalizationCsvData.IdRecordValue[sheet.GetValue(i + row, column)]; } } return(result); }
public static int[] ReadValueLocArray(CsvSpreadSheet sheet, int index, string headerName) { int row = sheet.GetRecord(index).StartRow; int column = sheet.GetHeaderRecord(headerName).Index; int len = sheet.GetRecord(index).HeaderContentLength[column]; int[] result = new int[len]; for (int i = 0; i < len; i++) { if (string.IsNullOrEmpty(sheet.GetValue(row + i, column))) { result[i] = 0; } else { result[i] = LocalizationCsvData.IdRecordValue[sheet.GetValue(i + row, column)]; } } return(result); }
public static decimal[] ReadValueDecimalArrayLine(CsvSpreadSheet sheet, int index, string headerName) { int row = sheet.GetRecord(index).StartRow; int column = sheet.GetHeaderRecord(headerName).Index; var v = sheet.GetValue(row, column); string[] line; if (string.IsNullOrEmpty(v)) { line = new string[0]; } else { line = sheet.GetValue(row, column).Split(new Char[] { '|', '#' }); } decimal[] result = new decimal[line.Length]; for (int i = 0; i < line.Length; i++) { result[i] = ParseDecimal(line[i]); } return(result); }
static void BuildLocalization() { string mapLevelFolder = "Assets/Build/Localization"; if (!Directory.Exists(mapLevelFolder)) { Directory.CreateDirectory(mapLevelFolder); } CsvReader.DOUBLEQUOTE = false; var csvReader = new CsvReader(); csvReader.Read("Assets/Build/Localization/Localization.csv"); CsvReader.DOUBLEQUOTE = true; int idIndex = -1; int valueIndex = -1; List <int> langList = new List <int>(); List <string> langStr = new List <string>(); for (int i = 0; i < csvReader.Width; i++) { if (csvReader.ReadCell(0, i).IndexOf("_ID") >= 0) { idIndex = i; } else if (csvReader.ReadCell(0, i).IndexOf("_VALUE") >= 0) { valueIndex = i; } else if (csvReader.ReadCell(0, i).IndexOf("Comment") < 0) { langList.Add(i); langStr.Add(csvReader.ReadCell(0, i).Remove(csvReader.ReadCell(0, i).IndexOf(":"))); } } for (int i = 0; i < langList.Count; i++) { using (StreamWriter sr = new StreamWriter(mapLevelFolder + "/Localization_" + langStr[i] + ".csv", false)) { string valueString = (valueIndex != -1)?",_VALUE":""; sr.WriteLine(csvReader.ReadCell(0, idIndex) + valueString + "," + "text:string"); for (int j = 1; j < csvReader.Height; j++) { string id = csvReader.ReadCell(j, idIndex); string val = (valueIndex != -1)?csvReader.ReadCell(j, valueIndex):(j.ToString()); //string val = csvReader.ReadCell(j, valueIndex); string text = csvReader.ReadCell(j, langList[i]); if (text.IndexOf(",") > 0 || text.IndexOf("\"") > 0 || text.IndexOf("\n") > 0 || text.IndexOf("\r") > 0 || (text.Length >= 3 && text[0] == '"' && text[1] == '"' && text[2] != '"')) { text = "\"" + text + "\""; } string finalVal = (valueIndex != -1)?("," + val):""; sr.WriteLine(id + finalVal + "," + text); } } } AssetDatabase.Refresh(); // create localizationcsvdata.cs CsvSpreadSheet localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/Localization_CN", true); localizationSheet.CsvFileName = "Assets/Build/Localization/Localization"; var tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile2(localizationSheet); FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile)))); AssetDatabase.Refresh(); // csvReader = new CsvReader(); // csvReader.Read("Assets/Build/Localization/RandomName.csv"); // idIndex = -1; // valueIndex = -1; // int maleSurname = -1; // int maleName = -1; // int femaleSurname = -1; // int femaleName = -1; // // for(int i = 0; i < csvReader.Width; i++) { // if(csvReader.ReadCell(0, i).IndexOf ("_ID") >= 0) { // idIndex = i; // } // else if(csvReader.ReadCell(0, i).IndexOf ("_VALUE") >= 0) { // valueIndex = i; // } // else if(csvReader.ReadCell(0, i).IndexOf ("MaleSurname") >=0 ) { // maleSurname = i; // } // else if(csvReader.ReadCell(0, i).IndexOf ("MaleName") >=0 ) { // maleName = i; // } // else if(csvReader.ReadCell(0, i).IndexOf ("FemaleSurname") >=0 ) { // femaleSurname = i; // } // else if(csvReader.ReadCell(0, i).IndexOf ("FemaleName") >=0 ) { // femaleName = i; // } // } // // int currentValue = 1; // int currentIndex = 0; // int currentHeight = 1; // for(int i = 0; i < langStr.Count; i++) { // using(StreamWriter sr = new StreamWriter(mapLevelFolder + "/RandomName_" + langStr[i] + ".csv", false)) { // sr.WriteLine("_INDEX,MaleSurname:string[],MaleName:string[],FemaleSurname:string[],FemaleName:string[]"); // for(int j = currentHeight; j < csvReader.Height; j++, currentIndex++) { // string val = csvReader.ReadCell(j, valueIndex); // if(!string.IsNullOrEmpty(val) && Int32.Parse(val) != currentValue) { // currentValue = Int32.Parse(val); // currentIndex = 0; // currentHeight = j; // break; // } // if(currentIndex == 0) { // sr.WriteLine(currentIndex.ToString() + "," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName)); // } // else { // sr.WriteLine("," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName)); // } // } // } // } // AssetDatabase.Refresh(); // // create localizationcsvdata.cs // localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/RandomName_CN", true); // localizationSheet.CsvFileName = "Assets/Build/Localization/RandomName"; // tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile(localizationSheet); // FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile)))); // AssetDatabase.Refresh(); }