diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginGroupAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginGroupAttributeDrawer.cs index e9570d75..b2426793 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginGroupAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginGroupAttributeDrawer.cs @@ -5,27 +5,40 @@ namespace Toolbox.Editor.Drawers { public class BeginGroupAttributeDrawer : ToolboxDecoratorDrawer { + 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) }; diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs index 67188270..31133547 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginHorizontalGroupAttributeDrawer.cs @@ -30,6 +30,18 @@ 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)) @@ -37,7 +49,8 @@ protected override void OnGuiBeginSafe(BeginHorizontalGroupAttribute attribute) lastFetchedWidth = layoutWidth; } - ToolboxLayoutHandler.BeginVertical(Style.groupBackgroundStyle); + var style = GetStyle(attribute.Style); + ToolboxLayoutHandler.BeginVertical(style); if (attribute.HasLabel) { GUILayout.Label(attribute.Label, EditorStyles.boldLabel); @@ -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) }; diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginGroupAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginGroupAttribute.cs index ea0ed878..d57038b7 100644 --- a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginGroupAttribute.cs +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginGroupAttribute.cs @@ -16,8 +16,18 @@ public BeginGroupAttribute(string label = null) Order = 1000; } - public string Label { get; private set; } - + /// + /// Optional label (header) that can be displayed at the group's top. + /// + public string Label { get; set; } public bool HasLabel => !string.IsNullOrEmpty(Label); + /// + /// Indicates what style should be used to render the group. + /// +#if UNITY_2019_3_OR_NEWER + public GroupStyle Style { get; set; } = GroupStyle.Round; +#else + public GroupStyle Style { get; set; } = GroupStyle.Boxed; +#endif } } \ No newline at end of file diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginHorizontalGroupAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginHorizontalGroupAttribute.cs index d670cd60..05eb2ab5 100644 --- a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginHorizontalGroupAttribute.cs +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/BeginHorizontalGroupAttribute.cs @@ -12,7 +12,7 @@ namespace UnityEngine [Conditional("UNITY_EDITOR")] public class BeginHorizontalGroupAttribute : BeginHorizontalAttribute { - public BeginHorizontalGroupAttribute() : base() + public BeginHorizontalGroupAttribute() : base() { WidthOffset = 32.0f; } @@ -23,9 +23,19 @@ public BeginHorizontalGroupAttribute(float labelToWidthRatio = 0.0f, float field Label = label; } + /// + /// Optional label (header) that can be displayed at the group's top. + /// public string Label { get; set; } - public bool HasLabel => !string.IsNullOrEmpty(Label); + /// + /// Indicates what style should be used to render the group. + /// +#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 /// diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs new file mode 100644 index 00000000..85cd53c3 --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs @@ -0,0 +1,8 @@ +namespace UnityEngine +{ + public enum GroupStyle + { + Round, + Boxed + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs.meta b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs.meta new file mode 100644 index 00000000..94ca0648 --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/GroupStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 42fc52af7fb44884490b52c427e6976f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs new file mode 100644 index 00000000..e3047a06 --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs @@ -0,0 +1,9 @@ +namespace UnityEngine +{ + public enum ListStyle + { + Round, + Boxed, + Lined + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs.meta b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs.meta new file mode 100644 index 00000000..0fd89b9d --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ListStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a709f8f155a7b5e4cbb55d48f074f47a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ReorderableListAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ReorderableListAttribute.cs index 7dc1290d..eeb76f9b 100644 --- a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ReorderableListAttribute.cs +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/PropertyListAttributes/ReorderableListAttribute.cs @@ -38,11 +38,4 @@ public ReorderableListAttribute(ListStyle style = ListStyle.Round, string elemen /// public bool HasLabels { get; set; } = true; } - - public enum ListStyle - { - Round, - Boxed, - Lined - } } \ No newline at end of file diff --git a/Assets/Examples/Scripts/SampleBehaviour4.cs b/Assets/Examples/Scripts/SampleBehaviour4.cs index e0ea78bf..c66d21a3 100644 --- a/Assets/Examples/Scripts/SampleBehaviour4.cs +++ b/Assets/Examples/Scripts/SampleBehaviour4.cs @@ -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; @@ -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]