protected override void OnDrawContent() { if (!witConfiguration || witConfigs.Length > 1) { DrawWitConfigurationPopup(); if (!witConfiguration) { GUILayout.Label( "A Wit configuration must be available and selected to test utterances.", EditorStyles.helpBox); return; } } if (string.IsNullOrEmpty(witConfiguration.clientAccessToken)) { GUILayout.Label( "Your wit configuration has not yet been linked to a wit application. Make sure you have linked your account with Wit.ai.", WitStyles.WordwrappedLabel); if (GUILayout.Button("Select Configuration")) { EditorGUIUtility.PingObject(witConfiguration); Selection.activeObject = witConfiguration; } return; } utterance = EditorGUILayout.TextField("Utterance", utterance); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Send", GUILayout.Width(75)) && (null == request || !request.IsActive)) { responseText = ""; if (!string.IsNullOrEmpty(utterance)) { SubmitUtterance(); } else { response = null; } } if (EditorApplication.isPlaying && wit) { if (!wit.Active && GUILayout.Button("Activate", GUILayout.Width(75))) { wit.Activate(); } if (wit.Active && GUILayout.Button("Deactivate", GUILayout.Width(75))) { wit.Deactivate(); } if (wit.Active && GUILayout.Button("Abort", GUILayout.Width(75))) { wit.DeactivateAndAbortRequest(); } } GUILayout.EndHorizontal(); if (wit && wit.MicActive) { BeginCenter(); GUILayout.Label("Listening..."); EndCenter(); } else if (wit && wit.IsRequestActive) { BeginCenter(); GUILayout.Label("Loading..."); EndCenter(); } else if (null != response) { GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandHeight(true)); DrawResponse(); GUILayout.EndVertical(); } else { GUILayout.BeginVertical(EditorStyles.helpBox); if (!string.IsNullOrEmpty(responseText)) { GUILayout.Label(responseText); } else { GUILayout.Label( "Enter an utterance and hit Send to see what your app will return."); } GUILayout.EndVertical(); } GUILayout.FlexibleSpace(); GUILayout.Label(status, WitStyles.BackgroundBlack25P); }
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(); }