@@ -53,7 +53,7 @@ static ToolboxEditorToolbar()
53
53
54
54
private static IEnumerator Initialize ( )
55
55
{
56
- while ( ToolboxEditorToolbar . toolbar == null )
56
+ while ( toolbar == null )
57
57
{
58
58
var toolbars = Resources . FindObjectsOfTypeAll ( toolbarType ) ;
59
59
if ( toolbars == null || toolbars . Length == 0 )
@@ -63,15 +63,15 @@ private static IEnumerator Initialize()
63
63
}
64
64
else
65
65
{
66
- ToolboxEditorToolbar . toolbar = toolbars [ 0 ] ;
66
+ toolbar = toolbars [ 0 ] ;
67
67
}
68
68
}
69
69
70
70
#if UNITY_2021_1_OR_NEWER
71
- var rootField = ToolboxEditorToolbar . toolbar . GetType ( ) . GetField ( "m_Root" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
72
- var root = rootField . GetValue ( ToolboxEditorToolbar . toolbar ) as VisualElement ;
73
- var toolbar = root . Q ( "ToolbarZoneLeftAlign" ) ;
71
+ var rootField = toolbar . GetType ( ) . GetField ( "m_Root" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
72
+ var root = rootField . GetValue ( toolbar ) as VisualElement ;
74
73
74
+ var toolbarLeftZone = root . Q ( "ToolbarZoneLeftAlign" ) ;
75
75
var element = new VisualElement ( )
76
76
{
77
77
style =
@@ -83,10 +83,25 @@ private static IEnumerator Initialize()
83
83
84
84
var container = new IMGUIContainer ( ) ;
85
85
container . style . flexGrow = 1 ;
86
- container . onGUIHandler += OnGui ;
87
-
86
+ container . onGUIHandler += OnGuiLeft ;
88
87
element . Add ( container ) ;
89
- toolbar . Add ( element ) ;
88
+ toolbarLeftZone . Add ( element ) ;
89
+
90
+ var toolbarRightZone = root . Q ( "ToolbarZoneRightAlign" ) ;
91
+ var rightElement = new VisualElement ( )
92
+ {
93
+ style =
94
+ {
95
+ flexGrow = 1 ,
96
+ flexDirection = FlexDirection . Row ,
97
+ }
98
+ } ;
99
+
100
+ var rightContainer = new IMGUIContainer ( ) ;
101
+ rightContainer . style . flexGrow = 1 ;
102
+ rightContainer . onGUIHandler += OnGuiRight ;
103
+ rightElement . Add ( rightContainer ) ;
104
+ toolbarRightZone . Add ( rightElement ) ;
90
105
#else
91
106
#if UNITY_2020_1_OR_NEWER
92
107
var backend = guiBackend . GetValue ( toolbar ) ;
@@ -101,23 +116,23 @@ private static IEnumerator Initialize()
101
116
var container = elements [ 0 ] as IMGUIContainer ;
102
117
#endif
103
118
var handler = onGuiHandler . GetValue ( container ) as Action ;
104
- handler -= OnGui ;
105
- handler += OnGui ;
119
+ handler -= OnGuiLeft ;
120
+ handler += OnGuiLeft ;
106
121
onGuiHandler . SetValue ( container , handler ) ;
107
122
#endif
108
123
}
109
124
110
- private static void OnGui ( )
125
+ private static void OnGuiLeft ( )
111
126
{
112
- if ( ! IsToolbarAllowed || ! IsToolbarValid )
127
+ if ( ! IsToolbarAllowed || ! IsLeftToolbarValid )
113
128
{
114
129
return ;
115
130
}
116
131
117
132
#if UNITY_2021_1_OR_NEWER
118
133
using ( new GUILayout . HorizontalScope ( ) )
119
134
{
120
- OnToolbarGui . Invoke ( ) ;
135
+ OnToolbarGuiLeft ( ) ;
121
136
}
122
137
#else
123
138
var screenWidth = EditorGUIUtility . currentViewWidth ;
@@ -139,12 +154,25 @@ private static void OnGui()
139
154
{
140
155
using ( new GUILayout . HorizontalScope ( ) )
141
156
{
142
- OnToolbarGui ? . Invoke ( ) ;
157
+ OnToolbarGuiLeft ( ) ;
143
158
}
144
159
}
145
160
#endif
146
161
}
147
162
163
+ private static void OnGuiRight ( )
164
+ {
165
+ if ( ! IsToolbarAllowed || ! IsRightToolbarValid )
166
+ {
167
+ return ;
168
+ }
169
+
170
+ using ( new EditorGUILayout . HorizontalScope ( ) )
171
+ {
172
+ OnToolbarGuiRight ( ) ;
173
+ }
174
+ }
175
+
148
176
public static void Repaint ( )
149
177
{
150
178
if ( toolbar == null )
@@ -156,11 +184,17 @@ public static void Repaint()
156
184
}
157
185
158
186
public static bool IsToolbarAllowed { get ; set ; } = true ;
159
- public static bool IsToolbarValid => toolbar != null && OnToolbarGui != null ;
187
+ public static bool IsLeftToolbarValid => toolbar != null && OnToolbarGuiLeft != null ;
188
+ public static bool IsRightToolbarValid => toolbar != null && OnToolbarGuiRight != null ;
160
189
public static float FromToolsOffset { get ; set ; } = 400.0f ;
161
190
public static float FromStripOffset { get ; set ; } = 150.0f ;
162
191
192
+ #pragma warning disable 0067
193
+ [ Obsolete ( "Use OnToolbarGuiLeft instead" ) ]
163
194
public static event Action OnToolbarGui ;
195
+ #pragma warning restore 0067
196
+ public static event Action OnToolbarGuiLeft ;
197
+ public static event Action OnToolbarGuiRight ;
164
198
165
199
private static class Style
166
200
{
0 commit comments