@@ -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 -- ;
0 commit comments