コード例 #1
0
        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 = "";
            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;
            }

            string[]          sceneNames  = speechManager.GetSceneNames();
            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 = (line.scene != "") ? (line.scene + ".unity") : "";

                        if ((line.scene == "" && sceneFilter == 0) ||
                            sceneFilter == 1 ||
                            (line.scene != "" && sceneFilter > 1 && line.scene.EndsWith(selectedScene)) ||
                            (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)
            {
                if (rowSorting == RowSorting.ByID)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.lineID.CompareTo(b.lineID)); });
                }
                else if (rowSorting == RowSorting.ByDescription)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.description.CompareTo(b.description)); });
                }
                else if (rowSorting == RowSorting.ByType)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.textType.ToString().CompareTo(b.textType.ToString())); });
                }
                else if (rowSorting == RowSorting.ByAssociatedObject)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.owner.CompareTo(b.owner)); });
                }
                else if (rowSorting == RowSorting.ByScene)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.scene.CompareTo(b.owner)); });
                }
            }

            bool            fail   = false;
            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);

                    if (cellText.Contains(CSVReader.csvDelimiter))
                    {
                        fail = true;
                        ACDebug.LogError("Cannot export translation since line " + line.lineID.ToString() + " (" + line.text + ") contains the character '" + CSVReader.csvDelimiter + "'.");
                    }
                }
                output.Add(rowList.ToArray());
            }

            if (!fail)
            {
                int length = output.Count;

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int j = 0; j < length; j++)
                {
                    sb.AppendLine(string.Join(CSVReader.csvDelimiter, output[j]));
                }

                if (Serializer.CreateSaveFile(fileName, sb.ToString()))
                {
                    ACDebug.Log((exportLines.Count - 1).ToString() + " lines exported.");
                }
            }

            //this.Close ();
                        #endif
        }
コード例 #2
0
        private void CreateScript()
        {
                        #if UNITY_WEBPLAYER
            ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again.");
                        #else
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().speechManager == null)
            {
                ACDebug.LogError("Cannot create script sheet - no Speech Manager is assigned!");
                return;
            }

            SpeechManager speechManager = AdvGame.GetReferences().speechManager;
            languageIndex = Mathf.Max(languageIndex, 0);

            string suggestedFilename = "Adventure Creator";
            if (AdvGame.GetReferences().settingsManager)
            {
                suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName;
            }
            if (limitToCharacter && characterName != "")
            {
                suggestedFilename += " (" + characterName + ")";
            }
            if (limitToTag && tagID >= 0)
            {
                SpeechTag speechTag = speechManager.GetSpeechTag(tagID);
                if (speechTag != null && speechTag.label.Length > 0)
                {
                    suggestedFilename += " (" + speechTag.label + ")";
                }
            }
            suggestedFilename += " - ";
            if (languageIndex > 0)
            {
                suggestedFilename += speechManager.languages[languageIndex] + " ";
            }
            suggestedFilename += "script.html";

            string fileName = EditorUtility.SaveFilePanel("Save script file", "Assets", suggestedFilename, "html");
            if (fileName.Length == 0)
            {
                return;
            }

            string gameName = "Adventure Creator";
            if (AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.saveFileName.Length > 0)
            {
                gameName = AdvGame.GetReferences().settingsManager.saveFileName;
                if (languageIndex > 0)
                {
                    gameName += " (" + speechManager.languages[languageIndex] + ")";
                }
            }

            System.Text.StringBuilder script = new System.Text.StringBuilder();
            script.Append("<html>\n<head>\n");
            script.Append("<meta http-equiv='Content-Type' content='text/html;charset=ISO-8859-1' charset='UTF-8'>\n");
            script.Append("<title>" + gameName + "</title>\n");
            script.Append("<style> body, table, div, p, dl { font: 400 14px/22px Roboto,sans-serif; } footer { text-align: center; padding-top: 20px; font-size: 12px;} footer a { color: blue; text-decoration: none} </style>\n</head>\n");
            script.Append("<body>\n");

            script.Append("<h1>" + gameName + " - script sheet");
            if (limitToCharacter && characterName != "")
            {
                script.Append(" (" + characterName + ")");
            }
            script.Append("</h1>\n");
            script.Append("<h2>Created: " + DateTime.UtcNow.ToString("HH:mm dd MMMM, yyyy") + "</h2>\n");

            // By scene
            foreach (string sceneFile in speechManager.sceneFiles)
            {
                bool foundLinesInScene = false;

                foreach (SpeechLine line in speechManager.lines)
                {
                    int    slashPoint = sceneFile.LastIndexOf("/") + 1;
                    string sceneName  = sceneFile.Substring(slashPoint);

                    if (line.textType == AC_TextType.Speech &&
                        (line.scene == sceneFile || sceneName == (line.scene + ".unity")) &&
                        (!limitToCharacter || characterName == "" || line.owner == characterName || (line.isPlayer && characterName == "Player")) &&
                        (!limitToTag || line.tagID == tagID))
                    {
                        if (!foundLinesInScene)
                        {
                            script.Append("<hr/>\n<h3><b>Scene:</b> " + sceneName + "</h3>\n");
                            foundLinesInScene = true;
                        }

                        script.Append(line.Print(languageIndex));
                    }
                }
            }

            // No scene
            bool foundLinesInInventory = false;

            foreach (SpeechLine line in speechManager.lines)
            {
                if (line.scene == "" &&
                    line.textType == AC_TextType.Speech &&
                    (!limitToCharacter || characterName == "" || line.owner == characterName || (line.isPlayer && characterName == "Player")) &&
                    (!limitToTag || line.tagID == tagID))
                {
                    if (!foundLinesInInventory)
                    {
                        script.Append("<hr/>\n<h3>Scene-independent lines:</h3>\n");
                        foundLinesInInventory = true;
                    }

                    script.Append(line.Print(languageIndex));
                }
            }

            script.Append("<footer>Generated by <a href='http://adventurecreator.org' target=blank>Adventure Creator</a>, by Chris Burton</footer>\n");
            script.Append("</body>\n</html>");

            Serializer.CreateSaveFile(fileName, script.ToString());
                        #endif

            this.Close();
        }