AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SpeechInputSourceEditor.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEditor;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule
8 {
9  [CustomEditor(typeof(SpeechInputSource))]
10  public class SpeechInputSourceEditor : Editor
11  {
12  private SerializedProperty persistentKeywordsProperty;
13  private SerializedProperty recognizerStart;
14  private SerializedProperty confidenceLevel;
15  private SerializedProperty keywordsAndKeys;
16 
17  private void OnEnable()
18  {
19  persistentKeywordsProperty = serializedObject.FindProperty("PersistentKeywords");
20  recognizerStart = serializedObject.FindProperty("RecognizerStart");
21  confidenceLevel = serializedObject.FindProperty("recognitionConfidenceLevel");
22  keywordsAndKeys = serializedObject.FindProperty("Keywords");
23  }
24 
25  public override void OnInspectorGUI()
26  {
27  serializedObject.Update();
28 
29  // Recognizer options
30  EditorGUILayout.PropertyField(persistentKeywordsProperty);
31  EditorGUILayout.PropertyField(recognizerStart);
32  EditorGUILayout.PropertyField(confidenceLevel);
33 
34  // the Keywords field
35  ShowList(keywordsAndKeys);
36  serializedObject.ApplyModifiedProperties();
37 
38  // error and warning messages
39  if (keywordsAndKeys.arraySize == 0)
40  {
41  EditorGUILayout.HelpBox("No keywords have been assigned!", MessageType.Warning);
42  }
43  }
44 
45  private static GUIContent removeButtonContent = new GUIContent("-", "Remove keyword");
46  private static GUIContent addButtonContent = new GUIContent("+", "Add keyword");
47  private static GUILayoutOption miniButtonWidth = GUILayout.Width(20.0f);
48 
49  private static void ShowList(SerializedProperty list)
50  {
51  // property name with expansion widget
52  EditorGUILayout.PropertyField(list);
53 
54  if (list.isExpanded)
55  {
56  EditorGUI.indentLevel++;
57 
58  // header row
59  EditorGUILayout.BeginHorizontal();
60  EditorGUILayout.LabelField("Keyword");
61  EditorGUILayout.LabelField("Key Shortcut");
62  EditorGUILayout.EndHorizontal();
63 
64  // keyword rows
65  for (int index = 0; index < list.arraySize; index++)
66  {
67  EditorGUILayout.BeginHorizontal();
68  // the element
69  EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(index));
70  // the remove element button
71  if (GUILayout.Button(removeButtonContent, EditorStyles.miniButton, miniButtonWidth))
72  {
73  list.DeleteArrayElementAtIndex(index);
74  }
75  EditorGUILayout.EndHorizontal();
76  }
77 
78  // add button row
79  EditorGUILayout.BeginHorizontal();
80  GUILayout.FlexibleSpace();
81  // the add element button
82  if (GUILayout.Button(addButtonContent, EditorStyles.miniButton, miniButtonWidth))
83  {
84  list.InsertArrayElementAtIndex(list.arraySize);
85  }
86  EditorGUILayout.EndHorizontal();
87 
88  EditorGUI.indentLevel--;
89  }
90  }
91  }
92 }