@@ -31,6 +31,15 @@ public override void OnInspectorGUI()
3131 {
3232 EditorGUILayout . HelpBox ( "No keywords have been assigned!" , MessageType . Warning ) ;
3333 }
34+ else
35+ {
36+ SpeechInputHandler handler = this . target as SpeechInputHandler ;
37+ string duplicateKeyword = handler . keywords . GroupBy ( keyword => keyword . Keyword . ToLower ( ) ) . Where ( group => group . Count ( ) > 1 ) . Select ( group => group . Key ) . FirstOrDefault ( ) ;
38+ if ( duplicateKeyword != null )
39+ {
40+ EditorGUILayout . HelpBox ( "Keyword '" + duplicateKeyword + "' is assigned more than once!" , MessageType . Warning ) ;
41+ }
42+ }
3443 }
3544
3645 private static GUIContent removeButtonContent = new GUIContent ( "-" , "Remove keyword" ) ;
@@ -41,6 +50,11 @@ private void ShowList(SerializedProperty list)
4150 {
4251 EditorGUI . indentLevel ++ ;
4352
53+ // remove the keywords already assigned from the registered list
54+ GameObject selectedObject = Selection . activeGameObject ;
55+ SpeechInputHandler handler = this . target as SpeechInputHandler ;
56+ string [ ] availableKeywords = registeredKeywords . Except ( handler . keywords . Select ( keywordAndResponse => keywordAndResponse . Keyword ) ) . ToArray ( ) ;
57+
4458 // keyword rows
4559 for ( int index = 0 ; index < list . arraySize ; index ++ )
4660 {
@@ -50,20 +64,22 @@ private void ShowList(SerializedProperty list)
5064 bool elementExpanded = EditorGUILayout . PropertyField ( elementProperty ) ;
5165 GUILayout . FlexibleSpace ( ) ;
5266 // the remove element button
53- if ( GUILayout . Button ( removeButtonContent , EditorStyles . miniButton , miniButtonWidth ) )
67+ bool elementRemoved = GUILayout . Button ( removeButtonContent , EditorStyles . miniButton , miniButtonWidth ) ;
68+ if ( elementRemoved )
5469 {
5570 list . DeleteArrayElementAtIndex ( index ) ;
5671 }
5772 EditorGUILayout . EndHorizontal ( ) ;
5873
59- if ( elementExpanded )
74+ if ( ! elementRemoved && elementExpanded )
6075 {
6176 SerializedProperty keywordProperty = elementProperty . FindPropertyRelative ( "Keyword" ) ;
62- int previousSelection = ArrayUtility . IndexOf ( registeredKeywords , keywordProperty . stringValue ) ;
63- int currentSelection = EditorGUILayout . Popup ( "Keyword" , previousSelection , registeredKeywords ) ;
77+ string [ ] keywords = availableKeywords . Concat ( new [ ] { keywordProperty . stringValue } ) . OrderBy ( keyword => keyword ) . ToArray ( ) ;
78+ int previousSelection = ArrayUtility . IndexOf ( keywords , keywordProperty . stringValue ) ;
79+ int currentSelection = EditorGUILayout . Popup ( "Keyword" , previousSelection , keywords ) ;
6480 if ( currentSelection != previousSelection )
6581 {
66- keywordProperty . stringValue = registeredKeywords [ currentSelection ] ;
82+ keywordProperty . stringValue = keywords [ currentSelection ] ;
6783 }
6884
6985 SerializedProperty responseProperty = elementProperty . FindPropertyRelative ( "Response" ) ;
0 commit comments