Skip to content

Commit b246e10

Browse files
[SpeechInputHandler] fixed public property PascalCase. Minor formatting.
1 parent ccfc971 commit b246e10

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

Assets/HoloToolkit/Input/Scripts/Editor/SpeechInputHandlerEditor.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SpeechInputHandlerEditor : Editor
1616

1717
private void OnEnable()
1818
{
19-
keywordsProperty = serializedObject.FindProperty("keywords");
19+
keywordsProperty = serializedObject.FindProperty("Keywords");
2020
registeredKeywords = RegisteredKeywords().Distinct().ToArray();
2121
}
2222

@@ -33,29 +33,33 @@ public override void OnInspectorGUI()
3333
}
3434
else
3535
{
36-
SpeechInputHandler handler = (SpeechInputHandler)target;
37-
string duplicateKeyword = handler.keywords.GroupBy(keyword => keyword.Keyword.ToLower()).Where(group => group.Count() > 1).Select(group => group.Key).FirstOrDefault();
36+
var handler = (SpeechInputHandler)target;
37+
string duplicateKeyword = handler.Keywords
38+
.GroupBy(keyword => keyword.Keyword.ToLower())
39+
.Where(group => group.Count() > 1)
40+
.Select(group => group.Key).FirstOrDefault();
41+
3842
if (duplicateKeyword != null)
3943
{
4044
EditorGUILayout.HelpBox("Keyword '" + duplicateKeyword + "' is assigned more than once!", MessageType.Warning);
4145
}
4246
}
4347
}
4448

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);
49+
private static readonly GUIContent RemoveButtonContent = new GUIContent("-", "Remove keyword");
50+
private static readonly GUIContent AddButtonContent = new GUIContent("+", "Add keyword");
51+
private static readonly GUILayoutOption MiniButtonWidth = GUILayout.Width(20.0f);
4852

4953
private void ShowList(SerializedProperty list)
5054
{
5155
EditorGUI.indentLevel++;
5256

5357
// remove the keywords already assigned from the registered list
54-
SpeechInputHandler handler = (SpeechInputHandler)target;
58+
var handler = (SpeechInputHandler)target;
5559

56-
if (handler.keywords == null) { return; }
60+
if (handler.Keywords == null) { return; }
5761

58-
string[] availableKeywords = registeredKeywords.Except(handler.keywords.Select(keywordAndResponse => keywordAndResponse.Keyword)).ToArray();
62+
string[] availableKeywords = registeredKeywords.Except(handler.Keywords.Select(keywordAndResponse => keywordAndResponse.Keyword)).ToArray();
5963

6064
// keyword rows
6165
for (int index = 0; index < list.arraySize; index++)
@@ -66,11 +70,13 @@ private void ShowList(SerializedProperty list)
6670
bool elementExpanded = EditorGUILayout.PropertyField(elementProperty);
6771
GUILayout.FlexibleSpace();
6872
// the remove element button
69-
bool elementRemoved = GUILayout.Button(removeButtonContent, EditorStyles.miniButton, miniButtonWidth);
73+
bool elementRemoved = GUILayout.Button(RemoveButtonContent, EditorStyles.miniButton, MiniButtonWidth);
74+
7075
if (elementRemoved)
7176
{
7277
list.DeleteArrayElementAtIndex(index);
7378
}
79+
7480
EditorGUILayout.EndHorizontal();
7581

7682
if (!elementRemoved && elementExpanded)
@@ -79,6 +85,7 @@ private void ShowList(SerializedProperty list)
7985
string[] keywords = availableKeywords.Concat(new[] { keywordProperty.stringValue }).OrderBy(keyword => keyword).ToArray();
8086
int previousSelection = ArrayUtility.IndexOf(keywords, keywordProperty.stringValue);
8187
int currentSelection = EditorGUILayout.Popup("Keyword", previousSelection, keywords);
88+
8289
if (currentSelection != previousSelection)
8390
{
8491
keywordProperty.stringValue = keywords[currentSelection];
@@ -92,11 +99,13 @@ private void ShowList(SerializedProperty list)
9299
// add button row
93100
EditorGUILayout.BeginHorizontal();
94101
GUILayout.FlexibleSpace();
102+
95103
// the add element button
96-
if (GUILayout.Button(addButtonContent, EditorStyles.miniButton, miniButtonWidth))
104+
if (GUILayout.Button(AddButtonContent, EditorStyles.miniButton, MiniButtonWidth))
97105
{
98106
list.InsertArrayElementAtIndex(list.arraySize);
99107
}
108+
100109
EditorGUILayout.EndHorizontal();
101110

102111
EditorGUI.indentLevel--;

Assets/HoloToolkit/Input/Scripts/Voice/SpeechInputHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace HoloToolkit.Unity.InputModule
1010
{
1111
public class SpeechInputHandler : MonoBehaviour, ISpeechHandler
1212
{
13-
[System.Serializable]
13+
[Serializable]
1414
public struct KeywordAndResponse
1515
{
1616
[Tooltip("The keyword to handle.")]
@@ -20,21 +20,21 @@ public struct KeywordAndResponse
2020
}
2121

2222
[Tooltip("The keywords to be recognized and optional keyboard shortcuts.")]
23-
public KeywordAndResponse[] keywords;
23+
public KeywordAndResponse[] Keywords;
2424

2525
[NonSerialized]
2626
private readonly Dictionary<string, UnityEvent> responses = new Dictionary<string, UnityEvent>();
2727

28-
// Use this for initialization
2928
protected virtual void Start()
3029
{
3130
// Convert the struct array into a dictionary, with the keywords and the methods as the values.
3231
// This helps easily link the keyword recognized to the UnityEvent to be invoked.
33-
int keywordCount = keywords.Length;
32+
int keywordCount = Keywords.Length;
3433
for (int index = 0; index < keywordCount; index++)
3534
{
36-
KeywordAndResponse keywordAndResponse = keywords[index];
35+
KeywordAndResponse keywordAndResponse = Keywords[index];
3736
string keyword = keywordAndResponse.Keyword.ToLower();
37+
3838
if (responses.ContainsKey(keyword))
3939
{
4040
Debug.LogError("Duplicate keyword '" + keyword + "' specified in '" + gameObject.name + "'.");

Assets/HoloToolkit/Input/Scripts/Voice/SpeechInputSource.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace HoloToolkit.Unity.InputModule
2020
/// </summary>
2121
public partial class SpeechInputSource : BaseInputSource
2222
{
23-
[System.Serializable]
23+
[Serializable]
2424
public struct KeywordAndKeyCode
2525
{
2626
[Tooltip("The keyword to recognize.")]
@@ -51,10 +51,12 @@ protected override void Start()
5151
if (keywordCount > 0)
5252
{
5353
string[] keywords = new string[keywordCount];
54+
5455
for (int index = 0; index < keywordCount; index++)
5556
{
5657
keywords[index] = Keywords[index].Keyword;
5758
}
59+
5860
keywordRecognizer = new KeywordRecognizer(keywords);
5961
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
6062

0 commit comments

Comments
 (0)