|
9 | 9 | namespace BigasTools.Editor{ |
10 | 10 | public class DrawerMenu : EditorWindow |
11 | 11 | { |
| 12 | + int tab; |
12 | 13 | Vector2 scrollPos; |
| 14 | + static Drawer[] drawers; |
13 | 15 | static DrawerOption[] options; |
14 | | - public static void ShowWindow(DrawerOption[] _keys) { |
| 16 | + static DrawerOption[] mostUsedKeys; |
| 17 | + static DrawerOption[] numbers; |
| 18 | + public static void ShowWindow(Drawer[] drawer, DrawerOption[] _keys, DrawerOption[] _mostUsedKeys, DrawerOption[] _numbers) { |
15 | 19 | var window = GetWindow<DrawerMenu>(); |
16 | 20 | window.titleContent = new GUIContent("Drawer menu"); |
17 | 21 | window.Show(); |
18 | 22 | window.minSize = new Vector2(400,180); |
19 | 23 | options = _keys; |
| 24 | + drawers = drawer; |
| 25 | + mostUsedKeys = _mostUsedKeys; |
| 26 | + numbers = _numbers; |
20 | 27 | } |
21 | 28 |
|
22 | 29 | void OnGUI() |
23 | 30 | { |
24 | | - GUILayout.BeginVertical(EditorStyles.toolbar); |
25 | | - scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(400), GUILayout.Height(500)); |
26 | | - for (int i = 0; i < options.Length; i++) |
| 31 | + var s = new string[drawers.Length]; |
| 32 | + for (int i = 0; i < drawers.Length; i++) |
27 | 33 | { |
28 | | - options[i].Refresh(i); |
29 | | - if(GUILayout.Button(options[i].name, EditorStyles.toolbarButton)){ |
30 | | - options[i].onGUI(); |
31 | | - options[i].Update(); |
32 | | - }; |
33 | | - GUILayout.FlexibleSpace(); |
| 34 | + s[i] = drawers[i].name; |
34 | 35 | } |
| 36 | + tab = GUILayout.Toolbar(tab, s); |
| 37 | + Draw(tab); |
| 38 | + } |
| 39 | + |
| 40 | + void Draw(int r){ |
| 41 | + var groups = new List<DrawerOption[]>(); |
| 42 | + groups.Add(options); |
| 43 | + groups.Add(mostUsedKeys); |
| 44 | + groups.Add(numbers); |
| 45 | + |
| 46 | + var o = groups[r]; |
| 47 | + |
| 48 | + GUILayout.BeginVertical(EditorStyles.toolbar); |
| 49 | + scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(400), GUILayout.Height(500)); |
| 50 | + for (int i = 0; i < o.Length; i++) |
| 51 | + { |
| 52 | + o[i].Refresh(i); |
| 53 | + if(GUILayout.Button(o[i].name, EditorStyles.toolbarButton)){ |
| 54 | + o[i].onGUI(); |
| 55 | + o[i].Update(); |
| 56 | + }; |
| 57 | + GUILayout.FlexibleSpace(); |
| 58 | + } |
35 | 59 | GUILayout.EndVertical(); |
36 | 60 | GUILayout.EndScrollView(); |
37 | 61 | } |
38 | 62 | } |
39 | 63 | [System.Serializable] |
| 64 | + public class Drawer{ |
| 65 | + public Drawer(string name) |
| 66 | + { |
| 67 | + this.name = name; |
| 68 | + } |
| 69 | + |
| 70 | + public string name {set;get;} |
| 71 | + } |
| 72 | + [System.Serializable] |
40 | 73 | public abstract class DrawerOption{ |
41 | 74 | public string name {set;get;} |
42 | 75 |
|
|
0 commit comments