@@ -84,25 +84,42 @@ public override void OnInspectorGUI()
84
84
if ( m_ControlSchemeOptions != null && m_ControlSchemeOptions . Length > 1 ) // Don't show if <Any> is the only option.
85
85
{
86
86
// 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 ( ) ;
90
96
if ( selected != m_SelectedDefaultControlScheme )
91
97
{
92
98
if ( selected == 0 )
93
99
{
94
100
m_DefaultControlSchemeProperty . stringValue = null ;
95
101
}
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
+ }
96
108
else
97
109
{
98
- m_DefaultControlSchemeProperty . stringValue =
99
- m_ControlSchemeOptions [ selected ] . text ;
110
+ m_DefaultControlSchemeProperty . stringValue = m_ControlSchemeOptions [ selected ] . text ;
100
111
}
101
112
m_SelectedDefaultControlScheme = selected ;
102
113
}
114
+ // Restore the initial color
115
+ GUI . backgroundColor = currentBg ;
103
116
117
+
118
+ rect = EditorGUILayout . GetControlRect ( ) ;
119
+ label = EditorGUI . BeginProperty ( rect , m_AutoSwitchText , m_NeverAutoSwitchControlSchemesProperty ) ;
104
120
var neverAutoSwitchValueOld = m_NeverAutoSwitchControlSchemesProperty . boolValue ;
105
- var neverAutoSwitchValueNew = ! EditorGUILayout . Toggle ( m_AutoSwitchText , ! neverAutoSwitchValueOld ) ;
121
+ var neverAutoSwitchValueNew = ! EditorGUI . Toggle ( rect , label , ! neverAutoSwitchValueOld ) ;
122
+ EditorGUI . EndProperty ( ) ;
106
123
if ( neverAutoSwitchValueOld != neverAutoSwitchValueNew )
107
124
{
108
125
m_NeverAutoSwitchControlSchemesProperty . boolValue = neverAutoSwitchValueNew ;
@@ -112,9 +129,11 @@ public override void OnInspectorGUI()
112
129
if ( m_ActionMapOptions != null && m_ActionMapOptions . Length > 0 )
113
130
{
114
131
// 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 ,
117
135
m_ActionMapOptions ) ;
136
+ EditorGUI . EndProperty ( ) ;
118
137
if ( selected != m_SelectedDefaultActionMap )
119
138
{
120
139
if ( selected == 0 )
@@ -424,6 +443,7 @@ private void OnActionAssetChange()
424
443
m_ActionNames = null ;
425
444
m_SelectedDefaultActionMap = - 1 ;
426
445
m_SelectedDefaultControlScheme = - 1 ;
446
+ m_InvalidDefaultControlSchemeName = null ;
427
447
return ;
428
448
}
429
449
@@ -486,22 +506,36 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
486
506
487
507
// Read out control schemes.
488
508
var selectedDefaultControlScheme = playerInput . defaultControlScheme ;
509
+ m_InvalidDefaultControlSchemeName = null ;
489
510
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 ( ) ;
498
513
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
+ }
502
527
}
503
- if ( m_SelectedDefaultControlScheme <= 0 )
528
+ else
529
+ {
504
530
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
+ }
505
539
506
540
// Read out action maps.
507
541
var selectedDefaultActionMap = ! string . IsNullOrEmpty ( playerInput . defaultActionMap )
@@ -562,6 +596,7 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
562
596
[ NonSerialized ] private int [ ] m_ActionMapIndices ;
563
597
[ NonSerialized ] private int m_NumActionMaps ;
564
598
[ NonSerialized ] private int m_SelectedDefaultControlScheme ;
599
+ [ NonSerialized ] private string m_InvalidDefaultControlSchemeName ;
565
600
[ NonSerialized ] private GUIContent [ ] m_ControlSchemeOptions ;
566
601
[ NonSerialized ] private int m_SelectedDefaultActionMap ;
567
602
[ NonSerialized ] private GUIContent [ ] m_ActionMapOptions ;
0 commit comments