private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (speechManager == null || exportColumns == null || exportColumns.Count == 0 || speechManager.lines == null || speechManager.lines.Count == 0) { return; } string suggestedFilename = string.Empty; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } suggestedFilename += "GameText.csv"; string fileName = EditorUtility.SaveFilePanel("Export game text", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } List <SpeechLine> exportLines = new List <SpeechLine>(); foreach (SpeechLine line in speechManager.lines) { if (filterByType) { if (line.textType != typeFilter) { continue; } } if (filterByScene) { if (sceneNames != null && sceneNames.Length > sceneFilter) { string selectedScene = sceneNames[sceneFilter] + ".unity"; string scenePlusExtension = (string.IsNullOrEmpty(line.scene)) ? string.Empty : (line.scene + ".unity"); if ((string.IsNullOrEmpty(line.scene) && sceneFilter == 0) || sceneFilter == 1 || (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && line.scene.EndsWith(selectedScene)) || (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && scenePlusExtension.EndsWith(selectedScene))) { } else { continue; } } } if (filterByText) { if (!line.Matches(textFilter, filterSpeechLine)) { continue; } } if (filterByTag) { if (tagFilter == -1 || (tagFilter < speechManager.speechTags.Count && line.tagID == speechManager.speechTags[tagFilter].ID)) { } else { continue; } } exportLines.Add(new SpeechLine(line)); } if (doRowSorting) { switch (rowSorting) { case RowSorting.ByID: exportLines.Sort((a, b) => a.lineID.CompareTo(b.lineID)); break; case RowSorting.ByDescription: exportLines.Sort((a, b) => string.Compare(a.description, b.description, System.StringComparison.Ordinal)); break; case RowSorting.ByType: exportLines.Sort((a, b) => string.Compare(a.textType.ToString(), b.textType.ToString(), System.StringComparison.Ordinal)); break; case RowSorting.ByAssociatedObject: exportLines.Sort((a, b) => string.Compare(a.owner, b.owner, System.StringComparison.Ordinal)); break; case RowSorting.ByScene: exportLines.Sort((a, b) => string.Compare(a.scene, b.scene, System.StringComparison.Ordinal)); break; default: break; } } List <string[]> output = new List <string[]>(); string[] languagesArray = speechManager.languages.ToArray(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader(languagesArray)); } output.Add(headerList.ToArray()); foreach (SpeechLine line in exportLines) { List <string> rowList = new List <string>(); rowList.Add(line.lineID.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(line); rowList.Add(cellText); } output.Add(rowList.ToArray()); } string fileContents = CSVReader.CreateCSVGrid(output); if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents)) { int numLines = exportLines.Count; ACDebug.Log(numLines.ToString() + " line" + ((numLines != 1) ? "s" : string.Empty) + " exported."); } #endif }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (variablesManager == null || exportColumns == null || exportColumns.Count == 0) { return; } if (variableLocation == VariableLocation.Local && allScenes) { bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel"); if (!canProceed) { return; } if (!UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } } string suggestedFilename = ""; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } if (variableLocation == VariableLocation.Local && allScenes) { suggestedFilename += " All "; } suggestedFilename += variableLocation.ToString() + " Variables.csv"; string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } List <string[]> output = new List <string[]>(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader()); } output.Add(headerList.ToArray()); // Global if (variableLocation == VariableLocation.Global) { List <GVar> exportVars = new List <GVar>(); foreach (GVar globalVariable in variablesManager.vars) { exportVars.Add(new GVar(globalVariable)); } foreach (GVar exportVar in exportVars) { List <string> rowList = new List <string>(); rowList.Add(exportVar.id.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes); rowList.Add(cellText); } output.Add(rowList.ToArray()); } } // Local else if (variableLocation == VariableLocation.Local) { if (allScenes) { string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); if (FindObjectOfType <LocalVariables>()) { LocalVariables localVariables = FindObjectOfType <LocalVariables>(); if (localVariables != null) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, localVariables.localVars, sceneName); } } } if (string.IsNullOrEmpty(originalScene)) { UnityVersionHandler.NewScene(); } else { UnityVersionHandler.OpenScene(originalScene); } } else { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName); } } // Component else if (variableLocation == VariableLocation.Component) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); if (variables != null) { output = GatherOutput(output, variables.vars, sceneName); } } string fileContents = CSVReader.CreateCSVGrid(output); if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents)) { int numExported = output.Count - 1; if (numExported == 1) { ACDebug.Log("1 " + variableLocation + " variable exported."); } else { ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported."); } } #endif }