protected override void OnEnable() { base.OnEnable(); keywordsProperty = serializedObject.FindProperty("keywords"); persistentKeywordsProperty = serializedObject.FindProperty("persistentKeywords"); speechConfirmationTooltipPrefabProperty = serializedObject.FindProperty("speechConfirmationTooltipPrefab"); if (MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) { distinctRegisteredKeywords = SpeechKeywordUtility.GetDistinctRegisteredKeywords(); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); bool enabled = CheckMixedRealityToolkit(); if (enabled) { if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) { EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Warning); } if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile == null) { EditorGUILayout.HelpBox("No Input System Profile Found, be sure to specify a profile in the main configuration profile.", MessageType.Error); enabled = false; } else if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile == null) { EditorGUILayout.HelpBox("No Speech Commands profile Found, be sure to specify a profile in the Input System's configuration profile.", MessageType.Error); enabled = false; } } bool validKeywords = distinctRegisteredKeywords != null && distinctRegisteredKeywords.Count() != 0; // If we should be enabled but there are no valid keywords, alert developer if (enabled && !validKeywords) { distinctRegisteredKeywords = SpeechKeywordUtility.GetDistinctRegisteredKeywords(); EditorGUILayout.HelpBox("No keywords registered. Some properties may not be editable.\n\nKeywords can be registered via Speech Commands Profile on the Mixed Reality Toolkit's Configuration Profile.", MessageType.Error); } enabled = enabled && validKeywords; serializedObject.Update(); EditorGUILayout.PropertyField(persistentKeywordsProperty); EditorGUILayout.PropertyField(speechConfirmationTooltipPrefabProperty); bool wasGUIEnabled = GUI.enabled; GUI.enabled = enabled; ShowList(keywordsProperty); GUI.enabled = wasGUIEnabled; serializedObject.ApplyModifiedProperties(); // error and warning messages if (keywordsProperty.arraySize == 0) { EditorGUILayout.HelpBox("No keywords have been assigned!", MessageType.Warning); } else { var handler = (SpeechInputHandler)target; string duplicateKeyword = handler.Keywords .GroupBy(keyword => keyword.Keyword.ToLower()) .Where(group => group.Count() > 1) .Select(group => group.Key).FirstOrDefault(); if (duplicateKeyword != null) { EditorGUILayout.HelpBox($"Keyword \'{duplicateKeyword}\' is assigned more than once!", MessageType.Warning); } } }