// 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); }
// 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() + "%"); }
// 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); }
// 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(); }