99[ CanEditMultipleObjects ]
1010public class KeyCodeDrawer : PropertyDrawer
1111{
12- private KeyCode _selectedKey = KeyCode . None ;
13- private bool _bChangeKey = false ;
1412 SerializedProperty p ;
1513
1614 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
@@ -39,12 +37,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3937 // Get the KeyCode enum by converting the name to KeyCode.
4038 var propKey = ( KeyCode ) Enum . Parse ( typeof ( KeyCode ) , propEnumName ) ;
4139
42- // Only change the keys if they differ from the input selection and make sure
43- // not to override it with the default value.
44- if ( _selectedKey != propKey && _selectedKey != KeyCode . None ) {
45- _bChangeKey = true ;
46- }
47-
4840 string keyName = Enum . GetName ( typeof ( KeyCode ) , propKey ) ;
4941
5042 // Offset the button from the label.
@@ -58,7 +50,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
5850
5951 // Apply changes if necessary, this way, the default _selectedKey value
6052 // does not incorrectly override the property enum value.
61- if ( _bChangeKey ) {
53+ /* if (_bChangeKey) {
6254
6355 // Since we cannot set the enum value of the serialized property directly,
6456 // we need to get the enumValueIndex associated to the KeyCode name.
@@ -84,7 +76,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
8476
8577 _bChangeKey = false;
8678 return;
87- }
79+ }*/
8880
8981 EditorGUI . EndProperty ( ) ;
9082 }
@@ -105,7 +97,7 @@ private void selectKey()
10597 int i = 0 ;
10698 foreach ( KeyCode k in keyCodes ) {
10799 drawer [ i ] = new DrawerOption < KeyCode > ( ( ) => keys , k . ToString ( ) , key => {
108- _selectedKey = key ;
100+ // _selectedKey = key;
109101 p . enumValueIndex = 4 ; } , p ) ;
110102 keys [ i ++ ] = k ;
111103 }
0 commit comments