Skip to content

Commit 9bdec64

Browse files
committed
Possibility to style groups; remove Tags, Layers and Scripts drawers from the default Hierarchy settings
1 parent e711ab4 commit 9bdec64

File tree

10 files changed

+107
-28
lines changed

10 files changed

+107
-28
lines changed

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginGroupAttributeDrawer.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,40 @@ namespace Toolbox.Editor.Drawers
55
{
66
public class BeginGroupAttributeDrawer : ToolboxDecoratorDrawer<BeginGroupAttribute>
77
{
8+
private GUIStyle GetStyle(GroupStyle style)
9+
{
10+
switch (style)
11+
{
12+
default:
13+
case GroupStyle.Round:
14+
return Style.roundGroupBackgroundStyle;
15+
case GroupStyle.Boxed:
16+
return Style.boxedGroupBackgroundStyle;
17+
}
18+
}
19+
820
protected override void OnGuiBeginSafe(BeginGroupAttribute attribute)
921
{
10-
ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
22+
var style = GetStyle(attribute.Style);
23+
ToolboxLayoutHandler.BeginVertical(style);
1124
if (attribute.HasLabel)
1225
{
1326
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
1427
}
1528
}
1629

17-
1830
private static class Style
1931
{
20-
internal static readonly GUIStyle groupBackgroundStyle;
32+
internal static readonly GUIStyle roundGroupBackgroundStyle;
33+
internal static readonly GUIStyle boxedGroupBackgroundStyle;
2134

2235
static Style()
2336
{
24-
#if UNITY_2019_3_OR_NEWER
25-
groupBackgroundStyle = new GUIStyle("helpBox")
26-
#else
27-
groupBackgroundStyle = new GUIStyle("box")
28-
#endif
37+
roundGroupBackgroundStyle = new GUIStyle("helpBox")
38+
{
39+
padding = new RectOffset(13, 12, 5, 5)
40+
};
41+
boxedGroupBackgroundStyle = new GUIStyle("box")
2942
{
3043
padding = new RectOffset(13, 12, 5, 5)
3144
};

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,27 @@ private void HandleScrollView(float fixedHeight)
3030
storage.AppendItem(controlId, newScroll);
3131
}
3232

33+
private GUIStyle GetStyle(GroupStyle style)
34+
{
35+
switch (style)
36+
{
37+
default:
38+
case GroupStyle.Round:
39+
return Style.roundGroupBackgroundStyle;
40+
case GroupStyle.Boxed:
41+
return Style.boxedGroupBackgroundStyle;
42+
}
43+
}
44+
3345
protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
3446
{
3547
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
3648
{
3749
lastFetchedWidth = layoutWidth;
3850
}
3951

40-
ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
52+
var style = GetStyle(attribute.Style);
53+
ToolboxLayoutHandler.BeginVertical(style);
4154
if (attribute.HasLabel)
4255
{
4356
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
@@ -59,16 +72,17 @@ protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
5972

6073
private static class Style
6174
{
62-
internal static readonly GUIStyle groupBackgroundStyle;
75+
internal static readonly GUIStyle roundGroupBackgroundStyle;
76+
internal static readonly GUIStyle boxedGroupBackgroundStyle;
6377
internal static readonly GUIStyle scrollViewGroupStyle;
6478

6579
static Style()
6680
{
67-
#if UNITY_2019_3_OR_NEWER
68-
groupBackgroundStyle = new GUIStyle("helpBox")
69-
#else
70-
groupBackgroundStyle = new GUIStyle("box")
71-
#endif
81+
roundGroupBackgroundStyle = new GUIStyle("helpBox")
82+
{
83+
padding = new RectOffset(13, 12, 5, 5)
84+
};
85+
boxedGroupBackgroundStyle = new GUIStyle("box")
7286
{
7387
padding = new RectOffset(13, 12, 5, 5)
7488
};

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginGroupAttribute.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ public BeginGroupAttribute(string label = null)
1616
Order = 1000;
1717
}
1818

19-
public string Label { get; private set; }
20-
19+
/// <summary>
20+
/// Optional label (header) that can be displayed at the group's top.
21+
/// </summary>
22+
public string Label { get; set; }
2123
public bool HasLabel => !string.IsNullOrEmpty(Label);
24+
/// <summary>
25+
/// Indicates what style should be used to render the group.
26+
/// </summary>
27+
#if UNITY_2019_3_OR_NEWER
28+
public GroupStyle Style { get; set; } = GroupStyle.Round;
29+
#else
30+
public GroupStyle Style { get; set; } = GroupStyle.Boxed;
31+
#endif
2232
}
2333
}

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginHorizontalGroupAttribute.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace UnityEngine
1212
[Conditional("UNITY_EDITOR")]
1313
public class BeginHorizontalGroupAttribute : BeginHorizontalAttribute
1414
{
15-
public BeginHorizontalGroupAttribute() : base()
15+
public BeginHorizontalGroupAttribute() : base()
1616
{
1717
WidthOffset = 32.0f;
1818
}
@@ -23,9 +23,19 @@ public BeginHorizontalGroupAttribute(float labelToWidthRatio = 0.0f, float field
2323
Label = label;
2424
}
2525

26+
/// <summary>
27+
/// Optional label (header) that can be displayed at the group's top.
28+
/// </summary>
2629
public string Label { get; set; }
27-
2830
public bool HasLabel => !string.IsNullOrEmpty(Label);
31+
/// <summary>
32+
/// Indicates what style should be used to render the group.
33+
/// </summary>
34+
#if UNITY_2019_3_OR_NEWER
35+
public GroupStyle Style { get; set; } = GroupStyle.Round;
36+
#else
37+
public GroupStyle Style { get; set; } = GroupStyle.Boxed;
38+
#endif
2939

3040
#if UNITY_2019_1_OR_NEWER
3141
/// <summary>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace UnityEngine
2+
{
3+
public enum GroupStyle
4+
{
5+
Round,
6+
Boxed
7+
}
8+
}

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace UnityEngine
2+
{
3+
public enum ListStyle
4+
{
5+
Round,
6+
Boxed,
7+
Lined
8+
}
9+
}

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ReorderableListAttribute.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,4 @@ public ReorderableListAttribute(ListStyle style = ListStyle.Round, string elemen
3838
/// </summary>
3939
public bool HasLabels { get; set; } = true;
4040
}
41-
42-
public enum ListStyle
43-
{
44-
Round,
45-
Boxed,
46-
Lined
47-
}
4841
}

Assets/Examples/Scripts/SampleBehaviour4.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void TestStaticMethod()
4949

5050
[BeginGroup("Parent group")]
5151
public int y;
52-
[BeginGroup("Nested group")]
52+
[BeginGroup("Nested group", Style = GroupStyle.Boxed)]
5353
public int var14;
5454
[Line]
5555
public int var15;
@@ -81,7 +81,7 @@ private static void TestStaticMethod()
8181

8282
[Label("Horizontal Layout (Group)", skinStyle: SkinStyle.Box)]
8383

84-
[BeginHorizontalGroup(Label = "Horizontal Group", ControlFieldWidth = true, ElementsInLayout = 2)]
84+
[BeginHorizontalGroup(Label = "Horizontal Group", ControlFieldWidth = true, ElementsInLayout = 2, Style = GroupStyle.Round)]
8585
[ReorderableList(Foldable = true), InLineEditor]
8686
public GameObject[] gameObjects;
8787
[SpaceArea]

0 commit comments

Comments
 (0)