// Layout
        private bool LayoutVoiceData(TTSPreloadData preloadData, int voiceIndex, ref bool updated)
        {
            // Indent
            EditorGUI.indentLevel++;

            // Get data
            TTSPreloadVoiceData voiceData = preloadData.voices[voiceIndex];
            string voiceID = voiceData.presetVoiceID;

            if (string.IsNullOrEmpty(voiceID))
            {
                voiceID = "No Voice Selected";
            }
            voiceID = $"{(voiceIndex+1)} - {voiceID}";

            // Foldout
            GUILayout.BeginHorizontal();
            bool show = WitEditorUI.LayoutFoldout(new GUIContent(voiceID), voiceData);

            if (!show)
            {
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                return(true);
            }

            // Delete
            if (WitEditorUI.LayoutTextButton("Delete Voice"))
            {
                DeleteVoice(voiceIndex);
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                updated = true;
                return(false);
            }

            // Begin Voice Data
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel++;

            // Voice Text Field
            if (TtsService == null || _ttsVoiceIDs == null || _ttsVoiceIDs.Count == 0)
            {
                WitEditorUI.LayoutTextField(new GUIContent("Voice ID"), ref voiceData.presetVoiceID, ref updated);
            }
            // Voice Preset Select
            else
            {
                int  presetIndex   = _ttsVoiceIDs.IndexOf(voiceData.presetVoiceID);
                bool presetUpdated = false;
                WitEditorUI.LayoutPopup("Voice ID", _ttsVoiceIDs.ToArray(), ref presetIndex, ref presetUpdated);
                if (presetUpdated)
                {
                    voiceData.presetVoiceID = _ttsVoiceIDs[presetIndex];
                    string l = string.Empty;
                    TTSPreloadUtility.RefreshVoiceData(TtsService, voiceData, null, ref l);
                    updated = true;
                }
            }

            // Ensure phrases exist
            if (voiceData.phrases == null)
            {
                voiceData.phrases = new TTSPreloadPhraseData[] { };
            }

            // Phrase Foldout
            EditorGUILayout.BeginHorizontal();
            bool isLayout = WitEditorUI.LayoutFoldout(new GUIContent($"Phrases ({voiceData.phrases.Length})"),
                                                      voiceData.phrases);

            if (WitEditorUI.LayoutTextButton("Add Phrase"))
            {
                TTSPreloadPhraseData lastPhrase = voiceData.phrases.Length == 0 ? null : voiceData.phrases[voiceData.phrases.Length - 1];
                voiceData.phrases = AddArrayItem <TTSPreloadPhraseData>(voiceData.phrases, new TTSPreloadPhraseData()
                {
                    textToSpeak = lastPhrase?.textToSpeak,
                    clipID      = lastPhrase?.clipID
                });
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                updated = true;
                return(false);
            }
            EditorGUILayout.EndHorizontal();
            if (isLayout)
            {
                for (int p = 0; p < voiceData.phrases.Length; p++)
                {
                    if (!LayoutPhraseData(voiceData, p, ref updated))
                    {
                        break;
                    }
                }
            }

            // End Voice Data
            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
            return(true);
        }
        // Layout phrase data
        private bool LayoutPhraseData(TTSPreloadVoiceData voiceData, int phraseIndex, ref bool updated)
        {
            // Begin Phrase
            EditorGUI.indentLevel++;

            // Get data
            TTSPreloadPhraseData phraseData = voiceData.phrases[phraseIndex];
            string title = $"{(phraseIndex+1)} - {phraseData.textToSpeak}";

            // Foldout
            GUILayout.BeginHorizontal();
            bool show = WitEditorUI.LayoutFoldout(new GUIContent(title), phraseData);

            if (!show)
            {
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                return(true);
            }

            // Delete
            if (WitEditorUI.LayoutTextButton("Delete Phrase"))
            {
                voiceData.phrases = DeleteArrayItem <TTSPreloadPhraseData>(voiceData.phrases, phraseIndex);
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                updated = true;
                return(false);
            }

            // Begin phrase Data
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel++;

            // Phrase
            bool phraseChange = false;

            WitEditorUI.LayoutTextField(new GUIContent("Phrase"), ref phraseData.textToSpeak, ref phraseChange);
            if (phraseChange)
            {
                TTSPreloadUtility.RefreshPhraseData(TtsService, new TTSDiskCacheSettings()
                {
                    DiskCacheLocation = TTSDiskCacheLocation.Preload
                }, TtsService?.GetPresetVoiceSettings(voiceData.presetVoiceID), phraseData);
                updated = true;
            }

            // Clip
            string clipID = phraseData.clipID;

            WitEditorUI.LayoutTextField(new GUIContent("Clip ID"), ref clipID, ref phraseChange);

            // State
            Color  col        = GUI.color;
            Color  stateColor = Color.green;
            string stateValue = "Downloaded";

            if (!phraseData.downloaded)
            {
                if (phraseData.downloadProgress <= 0f)
                {
                    stateColor = Color.red;
                    stateValue = "Missing";
                }
                else
                {
                    stateColor = Color.yellow;
                    stateValue = $"Downloading {(phraseData.downloadProgress * 100f):00.0}%";
                }
            }
            GUI.color = stateColor;
            WitEditorUI.LayoutKeyLabel("State", stateValue);
            GUI.color = col;

            // End Phrase
            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
            return(true);
        }
示例#3
0
        protected override void LayoutContent()
        {
            // Get service
            VoiceService voiceService = null;

            // Runtime Mode
            if (Application.isPlaying)
            {
                // Refresh services
                if (_services == null)
                {
                    RefreshVoiceServices();
                }
                // Services missing
                if (_services == null || _serviceNames == null || _services.Length == 0)
                {
                    WitEditorUI.LayoutErrorLabel(WitTexts.Texts.UnderstandingViewerMissingServicesLabel);
                    return;
                }
                // Voice service select
                int  newService    = _currentService;
                bool serviceUpdate = false;
                GUILayout.BeginHorizontal();
                // Clamp
                if (newService < 0 || newService >= _services.Length)
                {
                    newService    = 0;
                    serviceUpdate = true;
                }
                // Layout
                WitEditorUI.LayoutPopup(WitTexts.Texts.UnderstandingViewerServicesLabel, _serviceNames, ref newService, ref serviceUpdate);
                // Update
                if (serviceUpdate)
                {
                    SetVoiceService(newService);
                }
                // Refresh
                if (WitEditorUI.LayoutTextButton(WitTexts.Texts.ConfigurationRefreshButtonLabel))
                {
                    RefreshVoiceServices();
                }
                GUILayout.EndHorizontal();
                // Ensure service exists
                voiceService = service;
            }
            // Editor Only
            else
            {
                // Configuration select
                base.LayoutContent();
                // Ensure configuration exists
                if (!witConfiguration)
                {
                    WitEditorUI.LayoutErrorLabel(WitTexts.Texts.UnderstandingViewerMissingConfigLabel);
                    return;
                }
                // Check client access token
                string clientAccessToken = witConfiguration.clientAccessToken;
                if (string.IsNullOrEmpty(clientAccessToken))
                {
                    WitEditorUI.LayoutErrorLabel(WitTexts.Texts.UnderstandingViewerMissingClientTokenLabel);
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (WitEditorUI.LayoutTextButton(WitTexts.Texts.UnderstandingViewerSettingsButtonLabel))
                    {
                        Selection.activeObject = witConfiguration;
                    }
                    GUILayout.EndHorizontal();
                    return;
                }
            }

            // Determine if input is allowed
            bool allowInput = !Application.isPlaying || (service != null && !service.Active);

            GUI.enabled = allowInput;

            // Utterance field
            bool updated = false;

            WitEditorUI.LayoutTextField(new GUIContent(WitTexts.Texts.UnderstandingViewerUtteranceLabel), ref _utterance, ref updated);

            // Begin Buttons
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            // Submit utterance
            if (allowInput && WitEditorUI.LayoutTextButton(WitTexts.Texts.UnderstandingViewerSubmitButtonLabel))
            {
                _responseText = "";
                if (!string.IsNullOrEmpty(_utterance))
                {
                    SubmitUtterance();
                }
                else
                {
                    _response = null;
                }
            }

            // Service buttons
            GUI.enabled = true;
            if (EditorApplication.isPlaying && voiceService)
            {
                if (!voiceService.Active)
                {
                    // Activate
                    if (WitEditorUI.LayoutTextButton(WitTexts.Texts.UnderstandingViewerActivateButtonLabel))
                    {
                        voiceService.Activate();
                    }
                }
                else
                {
                    // Deactivate
                    if (WitEditorUI.LayoutTextButton(WitTexts.Texts.UnderstandingViewerDeactivateButtonLabel))
                    {
                        voiceService.Deactivate();
                    }
                    // Abort
                    if (WitEditorUI.LayoutTextButton(WitTexts.Texts.UnderstandingViewerAbortButtonLabel))
                    {
                        voiceService.DeactivateAndAbortRequest();
                    }
                }
            }
            GUILayout.EndHorizontal();

            // Results
            GUILayout.BeginVertical(EditorStyles.helpBox);
            if (_response != null)
            {
                DrawResponse();
            }
            else if (voiceService && voiceService.MicActive)
            {
                WitEditorUI.LayoutWrapLabel(WitTexts.Texts.UnderstandingViewerListeningLabel);
            }
            else if (voiceService && voiceService.IsRequestActive)
            {
                WitEditorUI.LayoutWrapLabel(WitTexts.Texts.UnderstandingViewerLoadingLabel);
            }
            else if (string.IsNullOrEmpty(_responseText))
            {
                WitEditorUI.LayoutWrapLabel(WitTexts.Texts.UnderstandingViewerPromptLabel);
            }
            else
            {
                WitEditorUI.LayoutWrapLabel(_responseText);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
        }