@@ -18,7 +18,6 @@ public class ToolboxEditorSceneViewObjectSelector : EditorWindow
1818 private GameObject highlightedObject ;
1919 private Vector2 size ;
2020 private Vector2 buttonSize ;
21- private GUIStyle buttonStyle ;
2221 private static readonly Color selectionColor = new Color ( 0.50f , 0.70f , 1.00f ) ;
2322
2423 private int shiftMinSelectionId = - 1 ;
@@ -38,25 +37,14 @@ public static void Show(List<GameObject> gameObjects, Vector2 position)
3837 window . ShowAsDropDown ( rect , window . size ) ;
3938 }
4039
41- private void InitializeStyle ( )
42- {
43- buttonStyle = new GUIStyle ( GUI . skin . button ) ;
44- buttonStyle . alignment = TextAnchor . MiddleLeft ;
45- }
46-
4740 private Vector2 CalculateSize ( )
4841 {
49- if ( buttonStyle == null )
50- {
51- InitializeStyle ( ) ;
52- }
53-
5442 size = Vector2 . zero ;
5543
5644 foreach ( var go in gameObjects )
5745 {
5846 GUIContent content = EditorGUIUtility . ObjectContent ( go , typeof ( GameObject ) ) ;
59- Vector2 currentSize = buttonStyle . CalcSize ( content ) ;
47+ Vector2 currentSize = Style . buttonStyle . CalcSize ( content ) ;
6048 if ( currentSize . x > size . x )
6149 {
6250 size . x = currentSize . x ;
@@ -99,11 +87,6 @@ private void InitializeGameObjectPaths()
9987
10088 private void OnGUI ( )
10189 {
102- if ( buttonStyle == null )
103- {
104- InitializeStyle ( ) ;
105- }
106-
10790 if ( Event . current . type == EventType . Layout )
10891 {
10992 return ;
@@ -152,7 +135,7 @@ private void OnGUINormal()
152135 GUI . backgroundColor = selectionColor ;
153136 }
154137
155- if ( GUI . Button ( rect , content , buttonStyle ) )
138+ if ( GUI . Button ( rect , content , Style . buttonStyle ) )
156139 {
157140 GameObjectButtonPress ( i ) ;
158141 }
@@ -179,7 +162,7 @@ private void OnGUIMouseMove()
179162
180163 var content = EditorGUIUtility . ObjectContent ( gameObject , typeof ( GameObject ) ) ;
181164
182- GUI . Button ( rect , content , buttonStyle ) ;
165+ GUI . Button ( rect , content , Style . buttonStyle ) ;
183166
184167 if ( rect . Contains ( Event . current . mousePosition ) )
185168 {
@@ -345,5 +328,15 @@ private GameObject HighlightedObject
345328 }
346329 }
347330
331+ private static class Style
332+ {
333+ internal static readonly GUIStyle buttonStyle ;
334+
335+ static Style ( )
336+ {
337+ buttonStyle = new GUIStyle ( GUI . skin . button ) ;
338+ buttonStyle . alignment = TextAnchor . MiddleLeft ;
339+ }
340+ }
348341 }
349342}
0 commit comments