99namespace BigasTools . Editor {
1010 public class DrawerMenu : EditorWindow
1111 {
12+ Vector2 scrollPos ;
1213 static DrawerOption [ ] options ;
1314 public static void ShowWindow ( DrawerOption [ ] _keys ) {
1415 var window = GetWindow < DrawerMenu > ( ) ;
@@ -20,7 +21,8 @@ public static void ShowWindow(DrawerOption[] _keys) {
2021
2122 void OnGUI ( )
2223 {
23- GUILayout . BeginHorizontal ( EditorStyles . toolbar ) ;
24+ GUILayout . BeginVertical ( EditorStyles . toolbar ) ;
25+ scrollPos = EditorGUILayout . BeginScrollView ( scrollPos , GUILayout . Width ( 400 ) , GUILayout . Height ( 500 ) ) ;
2426 for ( int i = 0 ; i < options . Length ; i ++ )
2527 {
2628 options [ i ] . Refresh ( i ) ;
@@ -30,7 +32,8 @@ void OnGUI()
3032 } ;
3133 GUILayout . FlexibleSpace ( ) ;
3234 }
33-
35+ GUILayout . EndVertical ( ) ;
36+ GUILayout . EndScrollView ( ) ;
3437 }
3538 }
3639 [ System . Serializable ]
@@ -48,13 +51,16 @@ public class DrawerOption<T> : DrawerOption{
4851 private readonly SerializedProperty serializedProperty ;
4952 private T [ ] values ;
5053 private T value ;
54+ private int selected ;
55+ KeyCode _selectedKey ;
5156
52- public DrawerOption ( Func < T [ ] > getValues , string name , Action < T > setValue , SerializedProperty serializedProperty )
57+ public DrawerOption ( Func < T [ ] > getValues , string name , Action < T > setValue , SerializedProperty serializedProperty , KeyCode _selectedKey )
5358 {
5459 this . name = name ;
5560 this . getValues = getValues ;
5661 this . setValue = setValue ;
5762 this . serializedProperty = serializedProperty ;
63+ this . _selectedKey = _selectedKey ;
5864 }
5965
6066 public override void onGUI ( )
@@ -64,10 +70,28 @@ public override void onGUI()
6470 //setValue(value);
6571 }
6672 }
73+ void GetEnumIndex ( ) {
74+ string _selectedKeyName = Enum . GetName ( typeof ( KeyCode ) , _selectedKey ) ;
75+ var keyCodes = Enum . GetValues ( typeof ( KeyCode ) ) ;
76+
77+ int index = 0 ;
78+
79+ // Find the index of the selected key name.
80+ foreach ( string enumName in serializedProperty . enumNames ) {
81+
82+ if ( enumName == _selectedKeyName ) {
83+ break ;
84+ }
85+
86+ index ++ ;
87+ }
88+
89+ serializedProperty . enumValueIndex = index ;
90+ serializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
91+ }
6792 public override void Update ( )
6893 {
69- serializedProperty . enumValueIndex = 14 ;
70- Debug . Log ( serializedProperty . serializedObject . ApplyModifiedProperties ( ) ) ;
94+ GetEnumIndex ( ) ;
7195 }
7296 void onValueGUI ( T val ) {
7397 setValue ( val ) ;
0 commit comments