private static void ExportLanguage(DialogueDatabase database, string language, string baseFilename, EncodingType encodingType) { var filename = string.IsNullOrEmpty(language) ? baseFilename : Path.GetDirectoryName(baseFilename) + "/" + Path.GetFileNameWithoutExtension(baseFilename) + "_" + language + ".txt"; using (StreamWriter file = new StreamWriter(filename, false, EncodingTypeTools.GetEncoding(encodingType))) { ExportTextFields(database, file); } }
private void ExportLanguage(int languageIndex, string filename) { using (StreamWriter file = new StreamWriter(filename, false, EncodingTypeTools.GetEncoding(encodingType))) { for (int i = 0; i < table.fields.Count; i++) { file.WriteLine(table.fields[i].values[languageIndex]); } } }
private static void ExportFile(DialogueDatabase database, string language, string baseFilename, bool exportActors, EntrytagFormat entrytagFormat, EncodingType encodingType) { var filename = string.IsNullOrEmpty(language) ? baseFilename : Path.GetDirectoryName(baseFilename) + "/" + Path.GetFileNameWithoutExtension(baseFilename) + "_" + language + ".csv"; using (StreamWriter file = new StreamWriter(filename, false, EncodingTypeTools.GetEncoding(encodingType))) { ExportDatabaseProperties(database, file); if (exportActors) { ExportActors(database, file); } ExportConversations(database, language, entrytagFormat, file); } }
private void Export() { string newFilename = EditorUtility.SaveFilePanel("Export to CSV", EditorWindowTools.GetDirectoryName(csvFilename), csvFilename, "csv"); if (!string.IsNullOrEmpty(newFilename)) { csvFilename = newFilename; if (Application.platform == RuntimePlatform.WindowsEditor) { csvFilename = csvFilename.Replace("/", "\\"); } using (StreamWriter file = new StreamWriter(csvFilename, false, EncodingTypeTools.GetEncoding(encodingType))) { // Write heading: StringBuilder sb = new StringBuilder(); sb.Append("Field"); foreach (var language in table.languages) { sb.AppendFormat(",{0}", CSVExporter.CleanField(language)); } file.WriteLine(sb); // Write fields: foreach (var field in table.fields) { sb = new StringBuilder(); sb.Append(CSVExporter.CleanField(field.name)); foreach (var value in field.values) { sb.AppendFormat(",{0}", CSVExporter.CleanField(value)); } file.WriteLine(sb); } } EditorUtility.DisplayDialog("Export Complete", "The localized text table was exported to CSV (comma-separated values) format. ", "OK"); } }
private void Import() { if (!EditorUtility.DisplayDialog("Import CSV?", "Importing from CSV will overwrite the current contents. Are you sure?", "Import", "Cancel")) { return; } string newFilename = EditorUtility.OpenFilePanel("Import from CSV", EditorWindowTools.GetDirectoryName(csvFilename), "csv"); if (!string.IsNullOrEmpty(newFilename)) { csvFilename = newFilename; if (Application.platform == RuntimePlatform.WindowsEditor) { csvFilename = csvFilename.Replace("/", "\\"); } try { // Read the source file and combine multiline rows: var sourceLines = new List <string>(); var file = new StreamReader(csvFilename, EncodingTypeTools.GetEncoding(encodingType)); string line; while ((line = file.ReadLine()) != null) { sourceLines.Add(line.TrimEnd()); } file.Close(); CombineMultilineSourceLines(sourceLines); if (sourceLines.Count < 1) { throw new System.Exception("No lines read from CSV file."); } // Work with a temporary, new table: LocalizedTextTable newTable = ScriptableObject.CreateInstance <LocalizedTextTable>(); // Read heading: string[] values = CSVExporter.GetValues(sourceLines[0]); sourceLines.RemoveAt(0); newTable.languages = new List <string>(values); newTable.languages.RemoveAt(0); // Read fields: newTable.fields.Clear(); while (sourceLines.Count > 0) { values = CSVExporter.GetValues(sourceLines[0]); sourceLines.RemoveAt(0); LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField(); field.name = values[0]; for (int i = 1; i < values.Length; i++) { field.values.Add(values[i]); } newTable.fields.Add(field); } // If we got to the end, use the new table: table.languages.Clear(); foreach (var newLanguage in newTable.languages) { table.languages.Add(newLanguage); } table.fields.Clear(); foreach (var newField in newTable.fields) { LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField(); field.name = newField.name; field.values = new List <string>(newField.values); table.fields.Add(field); } DestroyImmediate(newTable); } catch (System.Exception e) { Debug.LogError(e.Message); EditorUtility.DisplayDialog("Import Failed", "There was an error importing the CSV file.", "OK"); } EditorUtility.DisplayDialog("Import Complete", "The localized text table was imported from " + newFilename + ".", "OK"); } }