1
- using UnityEditor ;
1
+ using Toolbox . Editor . Internal ;
2
+ using UnityEditor ;
2
3
using UnityEngine ;
3
4
4
5
namespace Toolbox . Editor . Drawers
@@ -28,29 +29,39 @@ private void OpenBuildSettings()
28
29
EditorWindow . GetWindow ( typeof ( BuildPlayerWindow ) ) ;
29
30
}
30
31
31
-
32
- protected override float GetPropertyHeightSafe ( SerializedProperty property , GUIContent label )
33
- {
34
- var lineHeight = EditorGUIUtility . singleLineHeight + EditorGUIUtility . standardVerticalSpacing ;
35
- return HasSceneDetails ( property )
36
- ? base . GetPropertyHeightSafe ( property , label ) + lineHeight * 2
37
- : base . GetPropertyHeightSafe ( property , label ) ;
38
- }
39
-
40
32
protected override void OnGUISafe ( Rect position , SerializedProperty property , GUIContent label )
41
33
{
34
+ var hasDetails = HasSceneDetails ( property ) ;
42
35
EditorGUI . BeginProperty ( position , label , property ) ;
43
36
position . height = EditorGUIUtility . singleLineHeight ;
44
- position = EditorGUI . PrefixLabel ( position , label ) ;
37
+ if ( hasDetails )
38
+ {
39
+ position . xMax -= Style . foldoutWidth ;
40
+ }
41
+
45
42
var sceneProperty = property . FindPropertyRelative ( "sceneReference" ) ;
46
- EditorGUI . ObjectField ( position , sceneProperty , GUIContent . none ) ;
43
+ EditorGUI . ObjectField ( position , sceneProperty , label ) ;
47
44
EditorGUI . EndProperty ( ) ;
48
45
49
- if ( ! HasSceneDetails ( property ) )
46
+ if ( hasDetails )
47
+ {
48
+ var prevXMin = position . xMin ;
49
+ position . xMin = position . xMax ;
50
+ position . xMax += Style . foldoutWidth ;
51
+ using ( new DisabledScope ( true ) )
52
+ {
53
+ property . isExpanded = GUI . Toggle ( position , property . isExpanded , Style . foldoutContent , Style . foldoutStyle ) ;
54
+ }
55
+
56
+ position . xMin = prevXMin ;
57
+ }
58
+
59
+ if ( ! hasDetails || ! property . isExpanded )
50
60
{
51
61
return ;
52
62
}
53
63
64
+ EditorGUI . indentLevel ++ ;
54
65
var sceneData = SceneData . GetSceneDataFromIndex ( property ) ;
55
66
var spacing = EditorGUIUtility . standardVerticalSpacing ;
56
67
position . y += EditorGUIUtility . singleLineHeight + spacing ;
@@ -64,20 +75,21 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
64
75
EditorGUI . LabelField ( position , Style . notInBuildContent ) ;
65
76
position . y += EditorGUIUtility . singleLineHeight + spacing ;
66
77
EditorGUI . EndDisabledGroup ( ) ;
67
- if ( GUI . Button ( position , Style . showDetailsContent ) )
78
+ var buttonRect = EditorGUI . IndentedRect ( position ) ;
79
+ if ( GUI . Button ( buttonRect , Style . showDetailsContent ) )
68
80
{
69
81
OpenBuildSettings ( ) ;
70
82
}
71
83
}
72
- }
73
84
85
+ EditorGUI . indentLevel -- ;
86
+ }
74
87
75
88
public override bool IsPropertyValid ( SerializedProperty property )
76
89
{
77
90
return property . type == nameof ( SerializedScene ) ;
78
91
}
79
92
80
-
81
93
private struct SceneData
82
94
{
83
95
public int index ;
@@ -134,10 +146,28 @@ public static SceneData GetSceneDataFromScene(SerializedProperty property)
134
146
135
147
private static class Style
136
148
{
149
+ internal const float foldoutWidth = 50.0f ;
150
+
151
+ internal static readonly GUIContent foldoutContent = new GUIContent ( "Details" , "Show/Hide Scene Details" ) ;
137
152
internal static readonly GUIContent buildIndexContent = new GUIContent ( "Build Index" ) ;
138
153
internal static readonly GUIContent isEnabledContent = new GUIContent ( "Is Enabled" ) ;
139
154
internal static readonly GUIContent notInBuildContent = new GUIContent ( "Not in Build" ) ;
140
155
internal static readonly GUIContent showDetailsContent = new GUIContent ( "Open Build Settings" ) ;
156
+
157
+ internal static readonly GUIStyle foldoutStyle ;
158
+
159
+ static Style ( )
160
+ {
161
+ foldoutStyle = new GUIStyle ( EditorStyles . miniButton )
162
+ {
163
+ #if UNITY_2019_3_OR_NEWER
164
+ fontSize = 10 ,
165
+ #else
166
+ fontSize = 9 ,
167
+ #endif
168
+ alignment = TextAnchor. MiddleCenter
169
+ } ;
170
+ }
141
171
}
142
172
}
143
173
}
0 commit comments