@@ -84,25 +84,42 @@ public override void OnInspectorGUI()
8484 if ( m_ControlSchemeOptions != null && m_ControlSchemeOptions . Length > 1 ) // Don't show if <Any> is the only option.
8585 {
8686 // Default control scheme picker.
87-
88- var selected = EditorGUILayout . Popup ( m_DefaultControlSchemeText , m_SelectedDefaultControlScheme ,
89- m_ControlSchemeOptions ) ;
87+ Color currentBg = GUI . backgroundColor ;
88+ // if the invalid DefaultControlSchemeName is selected set the popup draw the BG color in red
89+ if ( m_InvalidDefaultControlSchemeName != null && m_SelectedDefaultControlScheme == 1 )
90+ GUI . backgroundColor = Color . red ;
91+
92+ var rect = EditorGUILayout . GetControlRect ( ) ;
93+ var label = EditorGUI . BeginProperty ( rect , m_DefaultControlSchemeText , m_DefaultControlSchemeProperty ) ;
94+ var selected = EditorGUI . Popup ( rect , label , m_SelectedDefaultControlScheme , m_ControlSchemeOptions ) ;
95+ EditorGUI . EndProperty ( ) ;
9096 if ( selected != m_SelectedDefaultControlScheme )
9197 {
9298 if ( selected == 0 )
9399 {
94100 m_DefaultControlSchemeProperty . stringValue = null ;
95101 }
102+ // if there is an invalid default scheme name it will be at rank 1.
103+ // we use m_InvalidDefaultControlSchemeName to prevent usage of the string with "name<Not Found>"
104+ else if ( m_InvalidDefaultControlSchemeName != null && selected == 1 )
105+ {
106+ m_DefaultControlSchemeProperty . stringValue = m_InvalidDefaultControlSchemeName ;
107+ }
96108 else
97109 {
98- m_DefaultControlSchemeProperty . stringValue =
99- m_ControlSchemeOptions [ selected ] . text ;
110+ m_DefaultControlSchemeProperty . stringValue = m_ControlSchemeOptions [ selected ] . text ;
100111 }
101112 m_SelectedDefaultControlScheme = selected ;
102113 }
114+ // Restore the initial color
115+ GUI . backgroundColor = currentBg ;
103116
117+
118+ rect = EditorGUILayout . GetControlRect ( ) ;
119+ label = EditorGUI . BeginProperty ( rect , m_AutoSwitchText , m_NeverAutoSwitchControlSchemesProperty ) ;
104120 var neverAutoSwitchValueOld = m_NeverAutoSwitchControlSchemesProperty . boolValue ;
105- var neverAutoSwitchValueNew = ! EditorGUILayout . Toggle ( m_AutoSwitchText , ! neverAutoSwitchValueOld ) ;
121+ var neverAutoSwitchValueNew = ! EditorGUI . Toggle ( rect , label , ! neverAutoSwitchValueOld ) ;
122+ EditorGUI . EndProperty ( ) ;
106123 if ( neverAutoSwitchValueOld != neverAutoSwitchValueNew )
107124 {
108125 m_NeverAutoSwitchControlSchemesProperty . boolValue = neverAutoSwitchValueNew ;
@@ -112,9 +129,11 @@ public override void OnInspectorGUI()
112129 if ( m_ActionMapOptions != null && m_ActionMapOptions . Length > 0 )
113130 {
114131 // Default action map picker.
115-
116- var selected = EditorGUILayout . Popup ( m_DefaultActionMapText , m_SelectedDefaultActionMap ,
132+ var rect = EditorGUILayout . GetControlRect ( ) ;
133+ var label = EditorGUI . BeginProperty ( rect , m_DefaultActionMapText , m_DefaultActionMapProperty ) ;
134+ var selected = EditorGUI . Popup ( rect , label , m_SelectedDefaultActionMap ,
117135 m_ActionMapOptions ) ;
136+ EditorGUI . EndProperty ( ) ;
118137 if ( selected != m_SelectedDefaultActionMap )
119138 {
120139 if ( selected == 0 )
@@ -424,6 +443,7 @@ private void OnActionAssetChange()
424443 m_ActionNames = null ;
425444 m_SelectedDefaultActionMap = - 1 ;
426445 m_SelectedDefaultControlScheme = - 1 ;
446+ m_InvalidDefaultControlSchemeName = null ;
427447 return ;
428448 }
429449
@@ -486,22 +506,36 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
486506
487507 // Read out control schemes.
488508 var selectedDefaultControlScheme = playerInput . defaultControlScheme ;
509+ m_InvalidDefaultControlSchemeName = null ;
489510 m_SelectedDefaultControlScheme = 0 ;
490- var controlSchemes = asset . controlSchemes ;
491- m_ControlSchemeOptions = new GUIContent [ controlSchemes . Count + 1 ] ;
492- m_ControlSchemeOptions [ 0 ] = new GUIContent ( EditorGUIUtility . TrTextContent ( "<Any>" ) ) ;
493- ////TODO: sort alphabetically
494- for ( var i = 0 ; i < controlSchemes . Count ; ++ i )
495- {
496- var name = controlSchemes [ i ] . name ;
497- m_ControlSchemeOptions [ i + 1 ] = new GUIContent ( name ) ;
511+ ////TODO: sort alphabetically and ensure that the order is the same in the schemes editor
512+ var controlSchemesNames = asset . controlSchemes . Select ( cs => cs . name ) . ToList ( ) ;
498513
499- if ( selectedDefaultControlScheme != null && string . Compare ( name , selectedDefaultControlScheme ,
500- StringComparison . InvariantCultureIgnoreCase ) == 0 )
501- m_SelectedDefaultControlScheme = i + 1 ;
514+ // try to find the selected Default Control Scheme
515+ if ( ! string . IsNullOrEmpty ( selectedDefaultControlScheme ) )
516+ {
517+ // +1 since <Any> will be the first in the list
518+ m_SelectedDefaultControlScheme = 1 + controlSchemesNames . FindIndex ( name => string . Compare ( name , selectedDefaultControlScheme ,
519+ StringComparison . InvariantCultureIgnoreCase ) == 0 ) ;
520+ // if not found, will insert the invalid name next to <Any>
521+ if ( m_SelectedDefaultControlScheme == 0 )
522+ {
523+ m_InvalidDefaultControlSchemeName = selectedDefaultControlScheme ;
524+ m_SelectedDefaultControlScheme = 1 ;
525+ controlSchemesNames . Insert ( 0 , $ "{ selectedDefaultControlScheme } { L10n . Tr ( "<Not Found>" ) } ") ;
526+ }
502527 }
503- if ( m_SelectedDefaultControlScheme <= 0 )
528+ else
529+ {
504530 playerInput . defaultControlScheme = null ;
531+ }
532+
533+ m_ControlSchemeOptions = new GUIContent [ controlSchemesNames . Count + 1 ] ;
534+ m_ControlSchemeOptions [ 0 ] = new GUIContent ( EditorGUIUtility . TrTextContent ( "<Any>" ) ) ;
535+ for ( var i = 0 ; i < controlSchemesNames . Count ; ++ i )
536+ {
537+ m_ControlSchemeOptions [ i + 1 ] = new GUIContent ( controlSchemesNames [ i ] ) ;
538+ }
505539
506540 // Read out action maps.
507541 var selectedDefaultActionMap = ! string . IsNullOrEmpty ( playerInput . defaultActionMap )
@@ -562,6 +596,7 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
562596 [ NonSerialized ] private int [ ] m_ActionMapIndices ;
563597 [ NonSerialized ] private int m_NumActionMaps ;
564598 [ NonSerialized ] private int m_SelectedDefaultControlScheme ;
599+ [ NonSerialized ] private string m_InvalidDefaultControlSchemeName ;
565600 [ NonSerialized ] private GUIContent [ ] m_ControlSchemeOptions ;
566601 [ NonSerialized ] private int m_SelectedDefaultActionMap ;
567602 [ NonSerialized ] private GUIContent [ ] m_ActionMapOptions ;
0 commit comments