@@ -8,6 +8,31 @@ namespace Toolbox.Editor.Drawers
88{
99 public class EditorButtonAttributeDrawer : ToolboxDecoratorDrawer < EditorButtonAttribute >
1010 {
11+ private void DrawButton ( EditorButtonAttribute attribute )
12+ {
13+ var declaringObjects = GetDeclaringObjects ( ) ;
14+ if ( declaringObjects == null || declaringObjects . Length == 0 )
15+ {
16+ //NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope
17+ return ;
18+ }
19+
20+ var disable = ! IsClickable ( attribute , declaringObjects ) ;
21+ using ( new EditorGUI . DisabledScope ( disable ) )
22+ {
23+ var label = string . IsNullOrEmpty ( attribute . ExtraLabel )
24+ ? ObjectNames . NicifyVariableName ( attribute . MethodName )
25+ : attribute . ExtraLabel ;
26+ var tooltip = attribute . Tooltip ;
27+ var content = new GUIContent ( label , tooltip ) ;
28+
29+ if ( GUILayout . Button ( content , Style . buttonStyle ) )
30+ {
31+ CallMethods ( attribute , declaringObjects ) ;
32+ }
33+ }
34+ }
35+
1136 private MethodInfo GetMethod ( EditorButtonAttribute attribute , object [ ] targetObjects , string methodName )
1237 {
1338 var methodInfo = ReflectionUtility . GetMethod ( methodName , targetObjects ) ;
@@ -119,29 +144,25 @@ private void CallMethods(EditorButtonAttribute attribute, object[] targetObjects
119144 }
120145 }
121146
122- protected override void OnGuiCloseSafe ( EditorButtonAttribute attribute )
147+ protected override void OnGuiBeginSafe ( EditorButtonAttribute attribute )
123148 {
124- var declaringObjects = GetDeclaringObjects ( ) ;
125- if ( declaringObjects == null || declaringObjects . Length == 0 )
149+ if ( attribute . PositionType != ButtonPositionType . Above )
126150 {
127- //NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope
128151 return ;
129152 }
130153
131- var disable = ! IsClickable ( attribute , declaringObjects ) ;
132- using ( new EditorGUI . DisabledScope ( disable ) )
133- {
134- var label = string . IsNullOrEmpty ( attribute . ExtraLabel )
135- ? ObjectNames . NicifyVariableName ( attribute . MethodName )
136- : attribute . ExtraLabel ;
137- var tooltip = attribute . Tooltip ;
138- var content = new GUIContent ( label , tooltip ) ;
154+ DrawButton ( attribute ) ;
155+ }
139156
140- if ( GUILayout . Button ( content , Style . buttonStyle ) )
141- {
142- CallMethods ( attribute , declaringObjects ) ;
143- }
157+ protected override void OnGuiCloseSafe ( EditorButtonAttribute attribute )
158+ {
159+ if ( attribute . PositionType != ButtonPositionType . Default &&
160+ attribute . PositionType != ButtonPositionType . Below )
161+ {
162+ return ;
144163 }
164+
165+ DrawButton ( attribute ) ;
145166 }
146167
147168 private static class Style
0 commit comments