// Handles gui layout public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Return error if (property.serializedObject == null) { string missingText = GetLocalizedText(property, LocalizedMissingKey); WitEditorUI.LayoutErrorLabel(missingText); return; } // Show foldout if desired string titleText = GetLocalizedText(property, LocalizedTitleKey); if (FoldoutEnabled) { property.isExpanded = WitEditorUI.LayoutFoldout(new GUIContent(titleText), property.isExpanded); if (!property.isExpanded) { return; } } // Show title only else { WitEditorUI.LayoutLabel(titleText); } // Indent GUILayout.BeginVertical(); EditorGUI.indentLevel++; // Pre fields OnGUIPreFields(position, property, label); // Iterate all subfields WitPropertyEditType editType = EditType; const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; Type fieldType = fieldInfo.FieldType; if (fieldType.IsArray) { fieldType = fieldType.GetElementType(); } FieldInfo[] subfields = fieldType.GetFields(flags); for (int s = 0; s < subfields.Length; s++) { FieldInfo subfield = subfields[s]; if (ShouldLayoutField(property, subfield)) { LayoutField(s, property, subfield, editType); } } // Post fields OnGUIPostFields(position, property, label); // Undent EditorGUI.indentLevel--; GUILayout.EndVertical(); }
// Handles gui layout public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { string keyText = GetFieldStringValue(property, GetKeyFieldName()); string valueText = GetFieldStringValue(property, GetValueFieldName()); WitEditorUI.LayoutKeyLabel(keyText, valueText); }
// Layout entity override protected override void LayoutPropertyField(FieldInfo subfield, SerializedProperty subfieldProperty, GUIContent labelContent, bool canEdit) { // Handle all the same except entities if (canEdit || !string.Equals(subfield.Name, "entities")) { base.LayoutPropertyField(subfield, subfieldProperty, labelContent, canEdit); return; } // Entity foldout subfieldProperty.isExpanded = WitEditorUI.LayoutFoldout(labelContent, subfieldProperty.isExpanded); if (subfieldProperty.isExpanded) { EditorGUI.indentLevel++; if (subfieldProperty.arraySize == 0) { WitEditorUI.LayoutErrorLabel(WitTexts.Texts.ConfigurationEntitiesMissingLabel); } else { for (int i = 0; i < subfieldProperty.arraySize; i++) { SerializedProperty entityProp = subfieldProperty.GetArrayElementAtIndex(i); string entityPropName = entityProp.FindPropertyRelative("name").stringValue; WitEditorUI.LayoutLabel(entityPropName); } } EditorGUI.indentLevel--; } }
public override void OnInspectorGUI() { if (!handler.wit) { GUILayout.Label( "Wit component is not present in the scene. Add wit to scene to get intent and entity suggestions.", EditorStyles.helpBox); } if (handler && handler.wit && null == intentNames) { if (handler.wit is IWitRuntimeConfigProvider provider && null != provider.RuntimeConfiguration && provider.RuntimeConfiguration.witConfiguration) { provider.RuntimeConfiguration.witConfiguration.UpdateData(); intentNames = provider.RuntimeConfiguration.witConfiguration.intents.Select(i => i.name).ToArray(); intentIndex = Array.IndexOf(intentNames, handler.intent); } } WitEditorUI.FallbackPopup(serializedObject, "intent", intentNames, ref intentIndex); var confidenceProperty = serializedObject.FindProperty("confidence"); EditorGUILayout.PropertyField(confidenceProperty); GUILayout.Space(16); var eventProperty = serializedObject.FindProperty("onIntentTriggered"); EditorGUILayout.PropertyField(eventProperty); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { // Init if needed if (!_initialized || configuration != target) { Initialize(); _initialized = true; } // Draw header if (drawHeader) { WitEditorUI.LayoutHeaderButton(HeaderIcon, HeaderUrl); GUILayout.Space(WitStyles.HeaderPaddingBottom); EditorGUI.indentLevel++; } // Layout content LayoutContent(); // Undent if (drawHeader) { EditorGUI.indentLevel--; } }
public override void OnInspectorGUI() { var handler = target as SimpleStringEntityHandler; if (!handler) { return; } if (!handler.wit) { GUILayout.Label("Wit component is not present in the scene. Add wit to scene to get intent and entity suggestions.", EditorStyles.helpBox); } var intentChanged = WitEditorUI.LayoutSerializedObjectPopup(serializedObject, "intent", intentNames, ref intentIndex); if (intentChanged || null != intentNames && intentNames.Length > 0 && null == entityNames) { if (handler && handler.wit && null == intentNames) { if (handler.wit is IWitRuntimeConfigProvider provider && null != provider.RuntimeConfiguration && provider.RuntimeConfiguration.witConfiguration) { var entities = provider.RuntimeConfiguration.witConfiguration.intents[intentIndex]?.entities; if (null != entities) { entityNames = entities.Select((e) => e.name).ToArray(); entityIndex = Array.IndexOf(entityNames, handler.entity); } } } } WitEditorUI.LayoutSerializedObjectPopup(serializedObject, "entity", entityNames, ref entityIndex); var confidenceProperty = serializedObject.FindProperty("confidence"); EditorGUILayout.PropertyField(confidenceProperty); EditorGUILayout.Space(16); var formatProperty = serializedObject.FindProperty("format"); EditorGUILayout.PropertyField(formatProperty); GUILayout.Space(16); var eventProperty = serializedObject.FindProperty("onIntentEntityTriggered"); EditorGUILayout.PropertyField(eventProperty); serializedObject.ApplyModifiedProperties(); }
protected override void LayoutFields() { string serverTokenLabelText = WitTexts.Texts.SetupServerTokenLabel; serverTokenLabelText = serverTokenLabelText.Replace(WitStyles.WitLinkKey, WitStyles.WitLinkColor); if (GUILayout.Button(serverTokenLabelText, WitStyles.Label)) { Application.OpenURL(WitTexts.GetAppURL("", WitTexts.WitAppEndpointType.Settings)); } bool updated = false; WitEditorUI.LayoutPasswordField(null, ref serverToken, ref updated); }
// Clip data private void OnClipGUI(TTSClipData clip) { // Generation Settings WitEditorUI.LayoutKeyLabel("Text", clip.textToSpeak); WitEditorUI.LayoutKeyObjectLabels("Voice Settings", clip.voiceSettings); WitEditorUI.LayoutKeyObjectLabels("Cache Settings", clip.diskCacheSettings); // Clip Settings EditorGUILayout.TextField("Clip ID", clip.clipID); EditorGUILayout.ObjectField("Clip", clip.clip, typeof(AudioClip), true); // Load Settings WitEditorUI.LayoutKeyLabel("Load State", clip.loadState.ToString()); WitEditorUI.LayoutKeyLabel("Load Progress", (clip.loadProgress * 100f).ToString() + "%"); }
// Custom GUI private bool OnInspectorCustomGUI(FieldInfo fieldInfo) { // Custom layout if (string.Equals(fieldInfo.Name, "intent")) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Intent", EditorStyles.boldLabel); WitEditorUI.LayoutSerializedObjectPopup(serializedObject, "intent", _intentNames, ref _intentIndex); return(true); } // Layout intent triggered return(false); }
protected virtual void LayoutContent() { if (!string.IsNullOrEmpty(ContentSubheaderLabel)) { WitEditorUI.LayoutSubheaderLabel(ContentSubheaderLabel); GUILayout.Space(WitStyles.HeaderPaddingBottom * 2f); } GUILayout.BeginHorizontal(); GUILayout.Space(WitStyles.WizardFieldPadding); GUILayout.BeginVertical(); LayoutFields(); GUILayout.EndVertical(); GUILayout.Space(WitStyles.WizardFieldPadding); GUILayout.EndHorizontal(); }
// Layout Preload Data protected virtual void LayoutPreloadData() { // For updates bool updated = false; // Layout preload items GUILayout.Space(WitStyles.WindowPaddingBottom); GUILayout.BeginHorizontal(); WitEditorUI.LayoutSubheaderLabel("TTS Preload Data"); if (WitEditorUI.LayoutTextButton("Add Voice")) { AddVoice(); updated = true; } GUILayout.EndHorizontal(); EditorGUILayout.Space(); // Indent EditorGUI.indentLevel++; // Generate if (Settings.data == null) { Settings.data = new TTSPreloadData(); } if (Settings.data.voices == null) { Settings.data.voices = new TTSPreloadVoiceData[] { new TTSPreloadVoiceData() }; } // Begin scroll for (int v = 0; v < Settings.data.voices.Length; v++) { if (!LayoutVoiceData(Settings.data, v, ref updated)) { break; } } // Set dirty if (updated) { EditorUtility.SetDirty(Settings); } // Indent EditorGUI.indentLevel--; }
// Layout public override void OnInspectorGUI() { // Get settings if (Settings != target) { Settings = target as TTSPreloadSettings; } // Draw header WitEditorUI.LayoutHeaderButton(HeaderIcon, HeaderUrl); GUILayout.Space(WitStyles.HeaderPaddingBottom); // Layout actions LayoutPreloadActions(); // Layout data LayoutPreloadData(); }
// On gui protected override void OnGUI() { base.OnGUI(); EditorGUILayout.BeginHorizontal(); WitEditorUI.LayoutStatusLabel(_status); GUILayout.BeginVertical(GUILayout.Width(24)); GUILayout.Space(4); GUILayout.BeginHorizontal(); GUILayout.Space(4); var rect = GUILayoutUtility.GetLastRect(); if (null == _hamburgerButton) { // GUI.skin must be called from OnGUI _hamburgerButton = new GUIStyle(GUI.skin.GetStyle("PaneOptions")); _hamburgerButton.imagePosition = ImagePosition.ImageOnly; } var value = EditorGUILayout.Popup(-1, new string[] { "Save", "Copy to Clipboard" }, _hamburgerButton, GUILayout.Width(24)); if (-1 != value) { if (value == 0) { var path = EditorUtility.SaveFilePanel("Save Response Json", Application.dataPath, "result", "json"); if (!string.IsNullOrEmpty(path)) { File.WriteAllText(path, _response.ToString()); } } else { EditorGUIUtility.systemCopyBuffer = _response.ToString(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
// GUI public override void OnInspectorGUI() { // Get speaker if (_speaker == null) { _speaker = target as TTSSpeaker; } // Get voices if (_voices == null || (_voiceIndex >= 0 && _voiceIndex < _voices.Length && !string.Equals(_speaker.VoiceSettings.settingsID, _voices[_voiceIndex]))) { RefreshVoices(); } // Voice select EditorGUILayout.LabelField(UI_VOICE_HEADER, EditorStyles.boldLabel); // No voices found if (_voices == null || _voices.Length == 0) { EditorGUILayout.TextField(UI_VOICE_KEY, _speaker.presetVoiceID); } // Voice dropdown else { bool updated = false; WitEditorUI.LayoutPopup(UI_VOICE_KEY, _voices, ref _voiceIndex, ref updated); if (updated) { string newVoiceID = _voiceIndex >= 0 && _voiceIndex < _voices.Length ? _voices[_voiceIndex] : string.Empty; _speaker.presetVoiceID = newVoiceID; EditorUtility.SetDirty(_speaker); } } // Display default ui EditorGUILayout.Space(); EditorGUILayout.Space(); base.OnInspectorGUI(); }
private static void OnServiceGUI(TTSService service) { // Wrong type if (service.GetType() != typeof(TTSWit) || Application.isPlaying) { return; } // Get data string text = "Update Voice List"; bool canUpdate = true; if (IsUpdating) { text = "Updating Voice List"; canUpdate = false; } else if (IsLoading) { text = "Loading Voice List"; canUpdate = false; } // Layout update GUI.enabled = canUpdate; if (WitEditorUI.LayoutTextButton(text) && canUpdate) { TTSWit wit = service as TTSWit; UpdateVoices(wit.RequestSettings.configuration, null); } GUI.enabled = true; // Force an update if (!_forcedUpdate && canUpdate && (_voices == null || _voices.Length == 0)) { _forcedUpdate = true; TTSWit wit = service as TTSWit; UpdateVoices(wit.RequestSettings.configuration, null); } }
protected override void LayoutContent() { // Server access token GUILayout.BeginHorizontal(); bool updated = false; WitEditorUI.LayoutPasswordField(WitTexts.SettingsServerTokenContent, ref serverToken, ref updated); if (updated) { RelinkServerToken(false); } if (WitEditorUI.LayoutTextButton(WitTexts.Texts.SettingsRelinkButtonLabel)) { RelinkServerToken(true); } if (WitEditorUI.LayoutTextButton(WitTexts.Texts.SettingsAddButtonLabel)) { int newIndex = WitConfigurationUtility.CreateConfiguration(serverToken); if (newIndex != -1) { SetConfiguration(newIndex); } } GUILayout.EndHorizontal(); GUILayout.Space(WitStyles.ButtonMargin); // Configuration select base.LayoutContent(); // Update inspector if needed if (witInspector == null || witConfiguration == null || witInspector.configuration != witConfiguration) { SetWitEditor(); } // Layout configuration inspector if (witConfiguration && witInspector) { witInspector.OnInspectorGUI(); } }
// Layout property field protected virtual void LayoutPropertyField(FieldInfo subfield, SerializedProperty subfieldProperty, GUIContent labelContent, bool canEdit) { // If can edit or not array default layout if (canEdit || !subfield.FieldType.IsArray || subfieldProperty.arraySize <= 0) { EditorGUILayout.PropertyField(subfieldProperty, labelContent); return; } // If cannot edit, handle here subfieldProperty.isExpanded = WitEditorUI.LayoutFoldout(labelContent, subfieldProperty.isExpanded); if (subfieldProperty.isExpanded) { EditorGUI.indentLevel++; for (int i = 0; i < subfieldProperty.arraySize; i++) { SerializedProperty p = subfieldProperty.GetArrayElementAtIndex(i); EditorGUILayout.PropertyField(p); } EditorGUI.indentLevel--; } }
// Layout configuration data protected virtual void LayoutConfigurationData() { // Reset update bool updated = false; // Client access field WitEditorUI.LayoutPasswordField(WitTexts.ConfigurationClientTokenContent, ref configuration.clientAccessToken, ref updated); if (updated && string.IsNullOrEmpty(configuration.clientAccessToken)) { Debug.LogError("Client access token is not defined. Cannot perform requests with '" + configuration.name + "'."); } // Timeout field WitEditorUI.LayoutIntField(WitTexts.ConfigurationRequestTimeoutContent, ref configuration.timeoutMS, ref updated); // Updated if (updated) { EditorUtility.SetDirty(configuration); } // Show configuration app data LayoutConfigurationEndpoint(); }
private void LayoutConduitContent() { string manifestPath = configuration.ManifestEditorPath; manifestAvailable = File.Exists(manifestPath); var useConduit = (GUILayout.Toggle(configuration.useConduit, "Use Conduit (Beta)")); if (configuration.useConduit != useConduit) { configuration.useConduit = useConduit; EditorUtility.SetDirty(configuration); } EditorGUI.BeginDisabledGroup(!configuration.useConduit); { EditorGUI.indentLevel++; GUILayout.Space(EditorGUI.indentLevel * WitStyles.ButtonMargin); { GUILayout.BeginHorizontal(); if (WitEditorUI.LayoutTextButton(manifestAvailable ? "Update Manifest" : "Generate Manifest")) { GenerateManifest(configuration, configuration.openManifestOnGeneration); } GUI.enabled = manifestAvailable; if (WitEditorUI.LayoutTextButton("Select Manifest") && manifestAvailable) { Selection.activeObject = AssetDatabase.LoadAssetAtPath <TextAsset>(configuration.ManifestEditorPath); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(WitStyles.ButtonMargin); configuration.autoGenerateManifest = (GUILayout.Toggle(configuration.autoGenerateManifest, "Auto Generate")); } EditorGUI.indentLevel--; GUILayout.TextField($"Manifests generated: {Statistics.SuccessfulGenerations}"); } EditorGUI.EndDisabledGroup(); }
// Edit array private T[] EditArray <T>(T[] array, Action <List <T> > edit) { // Generate list List <T> list = new List <T>(); // Add array to list if (array != null) { list.AddRange(array); } // Call edit action edit(list); // Set to array T[] result = list.ToArray(); // Refresh foldout value WitEditorUI.SetFoldoutValue(result, WitEditorUI.GetFoldoutValue(array)); // Return array return(result); }
protected override bool DrawWizardGUI() { // Reapply title if needed if (titleContent != Title) { titleContent = Title; } // Layout window Vector2 size = Vector2.zero; WitEditorUI.LayoutWindow(ContentHeaderLabel, HeaderIcon, HeaderUrl, LayoutContent, ref scrollOffset, out size); // Set wizard to max width size.x = WitStyles.WindowMaxWidth; // Wizards add additional padding size.y += 70f; // Clamp wizard sizes maxSize = minSize = size; // True if valid server token return(false); }
// Handle Layout protected virtual void OnGUI() { Vector2 size; WitEditorUI.LayoutWindow(titleContent.text, HeaderIcon, HeaderUrl, LayoutContent, ref ScrollOffset, out size); }
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(); }
// GUI public override void OnInspectorGUI() { // Display default ui base.OnInspectorGUI(); // Get service if (_service == null) { _service = target as TTSService; } // Add additional gui onAdditionalGUI?.Invoke(_service); // Ignore if in editor if (!Application.isPlaying) { return; } // Add spaces EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Runtime Clip Cache", EditorStyles.boldLabel); // No clips TTSClipData[] clips = _service.GetAllRuntimeCachedClips(); if (clips == null || clips.Length == 0) { WitEditorUI.LayoutErrorLabel("No clips found"); return; } // Has clips _clipFoldout = WitEditorUI.LayoutFoldout(new GUIContent($"Clips: {clips.Length}"), _clipFoldout); if (_clipFoldout) { EditorGUI.indentLevel++; // Iterate clips foreach (TTSClipData clip in clips) { // Get display name string displayName = clip.textToSpeak; // Crop if too long if (displayName.Length > MAX_DISPLAY_TEXT) { displayName = displayName.Substring(0, MAX_DISPLAY_TEXT); } // Add voice setting id if (clip.voiceSettings != null) { displayName = $"{clip.voiceSettings.settingsID} - {displayName}"; } // Foldout if desired bool foldout = WitEditorUI.LayoutFoldout(new GUIContent(displayName), clip); if (foldout) { EditorGUI.indentLevel++; OnClipGUI(clip); EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; } }
protected virtual void LayoutContent() { // Begin vertical box GUILayout.BeginVertical(EditorStyles.helpBox); // Check for app name/id update ReloadAppData(); // Title Foldout GUILayout.BeginHorizontal(); string foldoutText = WitTexts.Texts.ConfigurationHeaderLabel; if (!string.IsNullOrEmpty(_appName)) { foldoutText = foldoutText + " - " + _appName; } _foldout = WitEditorUI.LayoutFoldout(new GUIContent(foldoutText), _foldout); // Refresh button if (CanConfigurationRefresh(configuration)) { if (string.IsNullOrEmpty(_appName)) { bool isValid = WitConfigurationUtility.IsServerTokenValid(_serverToken); GUI.enabled = isValid; if (WitEditorUI.LayoutTextButton(WitTexts.Texts.ConfigurationRefreshButtonLabel)) { ApplyServerToken(_serverToken); } } else { bool isRefreshing = configuration.IsRefreshingData(); GUI.enabled = !isRefreshing; if (WitEditorUI.LayoutTextButton(isRefreshing ? WitTexts.Texts.ConfigurationRefreshingButtonLabel : WitTexts.Texts.ConfigurationRefreshButtonLabel)) { SafeRefresh(); } } } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(WitStyles.ButtonMargin); // Show configuration app data if (_foldout) { // Indent EditorGUI.indentLevel++; // Server access token bool updated = false; WitEditorUI.LayoutPasswordField(WitTexts.ConfigurationServerTokenContent, ref _serverToken, ref updated); if (updated) { ApplyServerToken(_serverToken); } // Additional data if (configuration) { LayoutConfigurationData(); } // Undent EditorGUI.indentLevel--; } // End vertical box layout GUILayout.EndVertical(); GUILayout.BeginVertical(EditorStyles.helpBox); LayoutConduitContent(); GUILayout.EndVertical(); // Layout configuration request tabs LayoutConfigurationRequestTabs(); // Additional open wit button GUILayout.FlexibleSpace(); if (GUILayout.Button(OpenButtonLabel, WitStyles.TextButton)) { Application.OpenURL(HeaderUrl); } }
// Layout Preload Data protected virtual void LayoutPreloadActions() { // Layout preload actions EditorGUILayout.Space(); WitEditorUI.LayoutSubheaderLabel("TTS Preload Actions"); // Indent EditorGUI.indentLevel++; EditorGUILayout.Space(); // Hide when playing if (Application.isPlaying) { EditorUtility.ClearProgressBar(); WitEditorUI.LayoutErrorLabel("TTS preload actions cannot be performed at runtime."); EditorGUI.indentLevel--; return; } // Get TTS Service if needed TtsService = EditorGUILayout.ObjectField("TTS Service", TtsService, typeof(TTSService), true) as TTSService; if (TtsService == null) { EditorUtility.ClearProgressBar(); TtsService = GameObject.FindObjectOfType <TTSService>(); WitEditorUI.LayoutErrorLabel("You must add a TTS Service to the loaded scene in order perform TTS actions."); EditorGUI.indentLevel--; return; } if (TtsService != null && _ttsVoiceIDs == null) { _ttsVoiceIDs = GetVoiceIDs(TtsService); } // Begin buttons EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); // Import JSON GUILayout.Space(ACTION_BTN_INDENT * EditorGUI.indentLevel); if (WitEditorUI.LayoutTextButton("Refresh Data")) { RefreshData(); } GUILayout.Space(ACTION_BTN_INDENT); if (WitEditorUI.LayoutTextButton("Import JSON")) { EditorUtility.ClearProgressBar(); if (TTSPreloadUtility.ImportData(Settings)) { RefreshData(); } } // Clear disk cache GUI.enabled = TtsService != null; EditorGUILayout.Space(); Color col = GUI.color; GUI.color = Color.red; if (WitEditorUI.LayoutTextButton("Delete Cache")) { EditorUtility.ClearProgressBar(); TTSPreloadUtility.DeleteData(TtsService); RefreshData(); } // Preload disk cache GUILayout.Space(ACTION_BTN_INDENT); GUI.color = Color.green; if (WitEditorUI.LayoutTextButton("Preload Cache")) { DownloadClips(); } GUI.color = col; GUI.enabled = true; // End buttons EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // Indent EditorGUI.indentLevel--; }
// Draw a specific property protected virtual void LayoutField(int index, SerializedProperty property, FieldInfo subfield, WitPropertyEditType editType) { // Begin layout GUILayout.BeginHorizontal(); // Get label content string labelText = GetLocalizedText(property, subfield.Name); GUIContent labelContent = new GUIContent(labelText); // Determine if can edit bool canEdit = editType == WitPropertyEditType.FreeEdit || (editType == WitPropertyEditType.LockEdit && editIndex == index); bool couldEdit = GUI.enabled; GUI.enabled = canEdit; // Cannot edit, just show field SerializedProperty subfieldProperty = property.FindPropertyRelative(subfield.Name); if (!canEdit && subfieldProperty.type == "string") { // Get value text string valText = subfieldProperty.stringValue; if (string.IsNullOrEmpty(valText)) { valText = GetDefaultFieldValue(property, subfield); } // Layout key WitEditorUI.LayoutKeyLabel(labelText, valText); } // Can edit, allow edit else { GUILayout.BeginVertical(); LayoutPropertyField(subfield, subfieldProperty, labelContent, canEdit); GUILayout.EndVertical(); } // Reset GUI.enabled = couldEdit; // Lock Settings if (editType == WitPropertyEditType.LockEdit) { // Is Editing if (editIndex == index) { // Clear Edit if (WitEditorUI.LayoutIconButton(WitStyles.ResetIcon)) { editIndex = -1; string clearVal = ""; if (subfieldProperty.type != "string") { clearVal = GetDefaultFieldValue(property, subfield); } SetFieldStringValue(subfieldProperty, clearVal); GUI.FocusControl(null); } // Accept Edit if (WitEditorUI.LayoutIconButton(WitStyles.AcceptIcon)) { editIndex = -1; GUI.FocusControl(null); } } // Not Editing else { // Begin Editing if (WitEditorUI.LayoutIconButton(WitStyles.EditIcon)) { editIndex = index; GUI.FocusControl(null); } } } // End layout GUILayout.EndHorizontal(); }
// 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); }
// 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); }
// Tabs protected virtual void LayoutConfigurationRequestTabs() { // Indent EditorGUI.indentLevel++; // Iterate tabs if (_tabIds != null) { GUILayout.BeginHorizontal(); for (int i = 0; i < _tabIds.Length; i++) { // Enable if not selected GUI.enabled = _requestTab != i; // If valid and clicked, begin selecting string tabPropertyID = _tabIds[i]; if (ShouldTabShow(configuration, tabPropertyID)) { if (WitEditorUI.LayoutTabButton(GetTabText(configuration, tabPropertyID, true))) { _requestTab = i; } } // If invalid, stop selecting else if (_requestTab == i) { _requestTab = -1; } } GUI.enabled = true; GUILayout.EndHorizontal(); } // Layout selected tab using property id string propertyID = _requestTab >= 0 && _requestTab < _tabIds.Length ? _tabIds[_requestTab] : string.Empty; if (!string.IsNullOrEmpty(propertyID) && configuration != null) { SerializedObject serializedObj = new SerializedObject(configuration); SerializedProperty serializedProp = serializedObj.FindProperty(propertyID); if (serializedProp == null) { WitEditorUI.LayoutErrorLabel(GetTabText(configuration, propertyID, false)); } else if (!serializedProp.isArray) { EditorGUILayout.PropertyField(serializedProp); } else if (serializedProp.arraySize == 0) { WitEditorUI.LayoutErrorLabel(GetTabText(configuration, propertyID, false)); } else { for (int i = 0; i < serializedProp.arraySize; i++) { SerializedProperty serializedPropChild = serializedProp.GetArrayElementAtIndex(i); EditorGUILayout.PropertyField(serializedPropChild); } } serializedObj.ApplyModifiedProperties(); } // Undent EditorGUI.indentLevel--; }