Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# DS_Store
*.DS_Store

# Covers JetBrains IDEs
.idea
1 change: 1 addition & 0 deletions Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
25 changes: 18 additions & 7 deletions Alchemy/Assets/Alchemy/Editor/AlchemyGroupDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace Alchemy.Editor
/// </summary>
public abstract class AlchemyGroupDrawer
{
/// <summary>
/// ID used to identify the group.
/// </summary>
public string UniqueId => _uniqueId;

/// <summary>
/// Drawing order
/// </summary>
public int Order => _order;

/// <summary>
/// Create a visual element that will be the root of the group.
/// </summary>
Expand All @@ -20,16 +30,17 @@ public abstract class AlchemyGroupDrawer
/// <param name="attribute">Target attribute</param>
public virtual VisualElement GetGroupElement(Attribute attribute) => null;

/// <summary>
/// ID used to identify the group.
/// </summary>
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;
}
}
}
1 change: 1 addition & 0 deletions Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public GroupNode Find(Func<GroupNode, bool> predicate)
public void Add(GroupNode node)
{
children.Add(node);
children.Sort((a, b) => a.drawer.Order.CompareTo(b.drawer.Order));
node.Parent = this;
}

Expand Down
24 changes: 12 additions & 12 deletions Alchemy/Assets/Alchemy/Runtime/Inspector/GroupAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ namespace Alchemy.Inspector
/// </summary>
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; }
}
}
41 changes: 41 additions & 0 deletions Alchemy/Assets/Tests/GroupOrderTest.cs
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions Alchemy/Assets/Tests/GroupOrderTest.cs.meta

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