@@ -19,6 +19,9 @@ protected enum ElementType
19
19
Button ,
20
20
Toggle ,
21
21
DropDownButton ,
22
+ Separator ,
23
+ Custom ,
24
+ FlexibleSpace ,
22
25
}
23
26
24
27
protected class ToolbarButtonData
@@ -29,6 +32,8 @@ protected class ToolbarButtonData
29
32
public bool visible = true ;
30
33
public Action buttonCallback ;
31
34
public Action < bool > toggleCallback ;
35
+ public int size ;
36
+ public Action customDrawFunction ;
32
37
}
33
38
34
39
List < ToolbarButtonData > leftButtonDatas = new List < ToolbarButtonData > ( ) ;
@@ -66,6 +71,32 @@ protected ToolbarButtonData AddButton(GUIContent content, Action callback, bool
66
71
return data ;
67
72
}
68
73
74
+ protected void AddSeparator ( int sizeInPixels = 10 , bool left = true )
75
+ {
76
+ var data = new ToolbarButtonData {
77
+ type = ElementType . Separator ,
78
+ size = sizeInPixels ,
79
+ } ;
80
+ ( ( left ) ? leftButtonDatas : rightButtonDatas ) . Add ( data ) ;
81
+ }
82
+
83
+ protected void AddCustom ( Action imguiDrawFunction , bool left = true )
84
+ {
85
+ if ( imguiDrawFunction == null )
86
+ throw new ArgumentException ( "imguiDrawFunction can't be null" ) ;
87
+
88
+ var data = new ToolbarButtonData {
89
+ type = ElementType . Custom ,
90
+ customDrawFunction = imguiDrawFunction ,
91
+ } ;
92
+ ( ( left ) ? leftButtonDatas : rightButtonDatas ) . Add ( data ) ;
93
+ }
94
+
95
+ protected void AddFlexibleSpace ( bool left = true )
96
+ {
97
+ ( ( left ) ? leftButtonDatas : rightButtonDatas ) . Add ( new ToolbarButtonData { type = ElementType . FlexibleSpace } ) ;
98
+ }
99
+
69
100
protected ToolbarButtonData AddToggle ( string name , bool defaultValue , Action < bool > callback , bool left = true )
70
101
=> AddToggle ( new GUIContent ( name ) , defaultValue , callback , left ) ;
71
102
@@ -112,7 +143,7 @@ protected void RemoveButton(string name, bool left)
112
143
protected void HideButton ( string name )
113
144
{
114
145
leftButtonDatas . Concat ( rightButtonDatas ) . All ( b => {
115
- if ( b . content . text == name )
146
+ if ( b ? . content ? . text == name )
116
147
b . visible = false ;
117
148
return true ;
118
149
} ) ;
@@ -125,7 +156,7 @@ protected void HideButton(string name)
125
156
protected void ShowButton ( string name )
126
157
{
127
158
leftButtonDatas . Concat ( rightButtonDatas ) . All ( b => {
128
- if ( b . content . text == name )
159
+ if ( b ? . content ? . text == name )
129
160
b . visible = true ;
130
161
return true ;
131
162
} ) ;
@@ -174,6 +205,16 @@ void DrawImGUIButtonList(List< ToolbarButtonData > buttons)
174
205
if ( EditorGUILayout . DropdownButton ( button . content , FocusType . Passive , EditorStyles . toolbarDropDown ) )
175
206
button . buttonCallback ( ) ;
176
207
break ;
208
+ case ElementType . Separator :
209
+ EditorGUILayout . Separator ( ) ;
210
+ EditorGUILayout . Space ( button . size ) ;
211
+ break ;
212
+ case ElementType . Custom :
213
+ button . customDrawFunction ( ) ;
214
+ break ;
215
+ case ElementType . FlexibleSpace :
216
+ GUILayout . FlexibleSpace ( ) ;
217
+ break ;
177
218
}
178
219
}
179
220
}
0 commit comments