diff --git a/.gitignore b/.gitignore index 65723c4..0d1c401 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # DS_Store *.DS_Store + +# Covers JetBrains IDEs +.idea diff --git a/Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs b/Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs index 6b6117c..aefe3e5 100644 --- a/Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs +++ b/Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs @@ -25,6 +25,7 @@ internal static AlchemyGroupDrawer CreateGroupDrawer(PropertyGroupAttribute attr var drawerType = FindGroupDrawerType(attribute); var drawer = (AlchemyGroupDrawer)Activator.CreateInstance(drawerType); drawer.SetUniqueId("AlchemyGroupId_" + targetType.FullName + "_" + attribute.GroupPath); + drawer.SetOrder(attribute.Order); return drawer; } } diff --git a/Alchemy/Assets/Alchemy/Editor/AlchemyGroupDrawer.cs b/Alchemy/Assets/Alchemy/Editor/AlchemyGroupDrawer.cs index 788eada..95d02d3 100644 --- a/Alchemy/Assets/Alchemy/Editor/AlchemyGroupDrawer.cs +++ b/Alchemy/Assets/Alchemy/Editor/AlchemyGroupDrawer.cs @@ -8,6 +8,16 @@ namespace Alchemy.Editor /// public abstract class AlchemyGroupDrawer { + /// + /// ID used to identify the group. + /// + public string UniqueId => _uniqueId; + + /// + /// Drawing order + /// + public int Order => _order; + /// /// Create a visual element that will be the root of the group. /// @@ -20,16 +30,17 @@ public abstract class AlchemyGroupDrawer /// Target attribute public virtual VisualElement GetGroupElement(Attribute attribute) => null; - /// - /// ID used to identify the group. - /// - public string UniqueId => uniqueId; - - string uniqueId; + private string _uniqueId; + private int _order; internal void SetUniqueId(string id) { - this.uniqueId = id; + _uniqueId = id; + } + + internal void SetOrder(int order) + { + _order = order; } } } \ No newline at end of file diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs index 407618f..a64d15c 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs @@ -44,6 +44,7 @@ public GroupNode Find(Func predicate) public void Add(GroupNode node) { children.Add(node); + children.Sort((a, b) => a.drawer.Order.CompareTo(b.drawer.Order)); node.Parent = this; } diff --git a/Alchemy/Assets/Alchemy/Runtime/Inspector/GroupAttributes.cs b/Alchemy/Assets/Alchemy/Runtime/Inspector/GroupAttributes.cs index 7e8f1e8..db542e0 100644 --- a/Alchemy/Assets/Alchemy/Runtime/Inspector/GroupAttributes.cs +++ b/Alchemy/Assets/Alchemy/Runtime/Inspector/GroupAttributes.cs @@ -2,24 +2,24 @@ namespace Alchemy.Inspector { public sealed class GroupAttribute : PropertyGroupAttribute { - public GroupAttribute() : base() { } - public GroupAttribute(string groupPath) : base(groupPath) { } + public GroupAttribute(int order = 0) : base(order) { } + public GroupAttribute(string groupPath, int order = 0) : base(groupPath, order) { } } public sealed class BoxGroupAttribute : PropertyGroupAttribute { - public BoxGroupAttribute() : base() { } - public BoxGroupAttribute(string groupPath) : base(groupPath) { } + public BoxGroupAttribute(int order = 0) : base(order) { } + public BoxGroupAttribute(string groupPath, int order = 0) : base(groupPath, order) { } } public sealed class TabGroupAttribute : PropertyGroupAttribute { - public TabGroupAttribute(string tabName) : base() + public TabGroupAttribute(string tabName, int order = 0) : base(order) { TabName = tabName; } - public TabGroupAttribute(string groupPath, string tabName) : base(groupPath) + public TabGroupAttribute(string groupPath, string tabName, int order = 0) : base(groupPath, order) { TabName = tabName; } @@ -29,19 +29,19 @@ public TabGroupAttribute(string groupPath, string tabName) : base(groupPath) public sealed class FoldoutGroupAttribute : PropertyGroupAttribute { - public FoldoutGroupAttribute() : base() { } - public FoldoutGroupAttribute(string groupPath) : base(groupPath) { } + public FoldoutGroupAttribute(int order = 0) : base(order) { } + public FoldoutGroupAttribute(string groupPath, int order = 0) : base(groupPath, order) { } } public sealed class HorizontalGroupAttribute : PropertyGroupAttribute { - public HorizontalGroupAttribute() : base() { } - public HorizontalGroupAttribute(string groupPath) : base(groupPath) { } + public HorizontalGroupAttribute(int order = 0) : base(order) { } + public HorizontalGroupAttribute(string groupPath, int order = 0) : base(groupPath, order) { } } public sealed class InlineGroupAttribute : PropertyGroupAttribute { - public InlineGroupAttribute() : base() { } - public InlineGroupAttribute(string groupPath) : base(groupPath) { } + public InlineGroupAttribute(int order = 0) : base(order) { } + public InlineGroupAttribute(string groupPath, int order = 0) : base(groupPath, order) { } } } \ No newline at end of file diff --git a/Alchemy/Assets/Alchemy/Runtime/Inspector/PropertyGroupAttribute.cs b/Alchemy/Assets/Alchemy/Runtime/Inspector/PropertyGroupAttribute.cs index d94c1c2..3c3fe49 100644 --- a/Alchemy/Assets/Alchemy/Runtime/Inspector/PropertyGroupAttribute.cs +++ b/Alchemy/Assets/Alchemy/Runtime/Inspector/PropertyGroupAttribute.cs @@ -7,16 +7,20 @@ namespace Alchemy.Inspector /// public abstract class PropertyGroupAttribute : Attribute { - public PropertyGroupAttribute() + public PropertyGroupAttribute(int order = 0) { GroupPath = string.Empty; + Order = order; } - public PropertyGroupAttribute(string groupPath) + public PropertyGroupAttribute(string groupPath, int order = 0) { GroupPath = groupPath; + Order = order; } - + public string GroupPath { get; } + + public int Order { get; } } } \ No newline at end of file diff --git a/Alchemy/Assets/Tests/GroupOrderTest.cs b/Alchemy/Assets/Tests/GroupOrderTest.cs new file mode 100644 index 0000000..76d61d4 --- /dev/null +++ b/Alchemy/Assets/Tests/GroupOrderTest.cs @@ -0,0 +1,41 @@ +using Alchemy.Inspector; +using UnityEngine; + +public class GroupOrderTest : MonoBehaviour +{ + [Group("Group3", 30)] + [SerializeField] + private float _valueFloatGroup3; + + [Group("Group3", 30)] + [SerializeField] + private string _valueStringGroup3; + + [Group("Group2", 20)] + [SerializeField] + private string _valueStringGroup2; + + [Group("Group1", 10)] + [SerializeField] + private float _valueFloatGroup1; + + [Group("Group1", 10)] + [SerializeField] + private string _valueStringGroup1; + + [Group("Group2", 20)] + [SerializeField] + private float _valueFloatGroup2; + + [Group("Group3" , 30)] + [SerializeField] + private bool _valueBoolGroup3; + + [Group("Group2", 20)] + [SerializeField] + private bool _valueBoolGroup2; + + [Group("Group1", 10)] + [SerializeField] + private bool _valueBoolGroup1; +} diff --git a/Alchemy/Assets/Tests/GroupOrderTest.cs.meta b/Alchemy/Assets/Tests/GroupOrderTest.cs.meta new file mode 100644 index 0000000..5475c6a --- /dev/null +++ b/Alchemy/Assets/Tests/GroupOrderTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5fb7a64e5440e6847967067f376a2b47 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: