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(); }