Skip to content

Commit

Permalink
Possibility to style groups; remove Tags, Layers and Scripts drawers …
Browse files Browse the repository at this point in the history
…from the default Hierarchy settings
  • Loading branch information
arimger committed Jun 13, 2024
1 parent e711ab4 commit 9bdec64
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,40 @@ namespace Toolbox.Editor.Drawers
{
public class BeginGroupAttributeDrawer : ToolboxDecoratorDrawer<BeginGroupAttribute>
{
private GUIStyle GetStyle(GroupStyle style)
{
switch (style)
{
default:
case GroupStyle.Round:
return Style.roundGroupBackgroundStyle;
case GroupStyle.Boxed:
return Style.boxedGroupBackgroundStyle;
}
}

protected override void OnGuiBeginSafe(BeginGroupAttribute attribute)
{
ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
var style = GetStyle(attribute.Style);
ToolboxLayoutHandler.BeginVertical(style);
if (attribute.HasLabel)
{
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
}
}


private static class Style
{
internal static readonly GUIStyle groupBackgroundStyle;
internal static readonly GUIStyle roundGroupBackgroundStyle;
internal static readonly GUIStyle boxedGroupBackgroundStyle;

static Style()
{
#if UNITY_2019_3_OR_NEWER
groupBackgroundStyle = new GUIStyle("helpBox")
#else
groupBackgroundStyle = new GUIStyle("box")
#endif
roundGroupBackgroundStyle = new GUIStyle("helpBox")
{
padding = new RectOffset(13, 12, 5, 5)
};
boxedGroupBackgroundStyle = new GUIStyle("box")
{
padding = new RectOffset(13, 12, 5, 5)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ private void HandleScrollView(float fixedHeight)
storage.AppendItem(controlId, newScroll);
}

private GUIStyle GetStyle(GroupStyle style)
{
switch (style)
{
default:
case GroupStyle.Round:
return Style.roundGroupBackgroundStyle;
case GroupStyle.Boxed:
return Style.boxedGroupBackgroundStyle;
}
}

protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)
{
if (GuiLayoutUtility.TryGetLayoutWidth(out var layoutWidth))
{
lastFetchedWidth = layoutWidth;
}

ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle);
var style = GetStyle(attribute.Style);
ToolboxLayoutHandler.BeginVertical(style);
if (attribute.HasLabel)
{
GUILayout.Label(attribute.Label, EditorStyles.boldLabel);
Expand All @@ -59,16 +72,17 @@ protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute)

private static class Style
{
internal static readonly GUIStyle groupBackgroundStyle;
internal static readonly GUIStyle roundGroupBackgroundStyle;
internal static readonly GUIStyle boxedGroupBackgroundStyle;
internal static readonly GUIStyle scrollViewGroupStyle;

static Style()
{
#if UNITY_2019_3_OR_NEWER
groupBackgroundStyle = new GUIStyle("helpBox")
#else
groupBackgroundStyle = new GUIStyle("box")
#endif
roundGroupBackgroundStyle = new GUIStyle("helpBox")
{
padding = new RectOffset(13, 12, 5, 5)
};
boxedGroupBackgroundStyle = new GUIStyle("box")
{
padding = new RectOffset(13, 12, 5, 5)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ public BeginGroupAttribute(string label = null)
Order = 1000;
}

public string Label { get; private set; }

/// <summary>
/// Optional label (header) that can be displayed at the group's top.
/// </summary>
public string Label { get; set; }
public bool HasLabel => !string.IsNullOrEmpty(Label);
/// <summary>
/// Indicates what style should be used to render the group.
/// </summary>
#if UNITY_2019_3_OR_NEWER
public GroupStyle Style { get; set; } = GroupStyle.Round;
#else
public GroupStyle Style { get; set; } = GroupStyle.Boxed;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace UnityEngine
[Conditional("UNITY_EDITOR")]
public class BeginHorizontalGroupAttribute : BeginHorizontalAttribute
{
public BeginHorizontalGroupAttribute() : base()
public BeginHorizontalGroupAttribute() : base()
{
WidthOffset = 32.0f;
}
Expand All @@ -23,9 +23,19 @@ public BeginHorizontalGroupAttribute(float labelToWidthRatio = 0.0f, float field
Label = label;
}

/// <summary>
/// Optional label (header) that can be displayed at the group's top.
/// </summary>
public string Label { get; set; }

public bool HasLabel => !string.IsNullOrEmpty(Label);
/// <summary>
/// Indicates what style should be used to render the group.
/// </summary>
#if UNITY_2019_3_OR_NEWER
public GroupStyle Style { get; set; } = GroupStyle.Round;
#else
public GroupStyle Style { get; set; } = GroupStyle.Boxed;
#endif

#if UNITY_2019_1_OR_NEWER
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnityEngine
{
public enum GroupStyle
{
Round,
Boxed
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace UnityEngine
{
public enum ListStyle
{
Round,
Boxed,
Lined
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ public ReorderableListAttribute(ListStyle style = ListStyle.Round, string elemen
/// </summary>
public bool HasLabels { get; set; } = true;
}

public enum ListStyle
{
Round,
Boxed,
Lined
}
}
4 changes: 2 additions & 2 deletions Assets/Examples/Scripts/SampleBehaviour4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void TestStaticMethod()

[BeginGroup("Parent group")]
public int y;
[BeginGroup("Nested group")]
[BeginGroup("Nested group", Style = GroupStyle.Boxed)]
public int var14;
[Line]
public int var15;
Expand Down Expand Up @@ -81,7 +81,7 @@ private static void TestStaticMethod()

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

[BeginHorizontalGroup(Label = "Horizontal Group", ControlFieldWidth = true, ElementsInLayout = 2)]
[BeginHorizontalGroup(Label = "Horizontal Group", ControlFieldWidth = true, ElementsInLayout = 2, Style = GroupStyle.Round)]
[ReorderableList(Foldable = true), InLineEditor]
public GameObject[] gameObjects;
[SpaceArea]
Expand Down

0 comments on commit 9bdec64

Please sign in to comment.