Skip to content

Commit

Permalink
Add: LabelText argument for Button attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0127 committed Mar 16, 2024
1 parent bcaeef5 commit 879aa3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Alchemy/Assets/Alchemy/Editor/Elements/MethodButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using Alchemy.Inspector;
using UnityEditor;
using UnityEngine.UIElements;

Expand All @@ -17,7 +18,7 @@ public MethodButton(object target, MethodInfo methodInfo)
{
button = new Button(() => methodInfo.Invoke(target, null))
{
text = methodInfo.Name
text = methodInfo.GetCustomAttribute<ButtonAttribute>().LabelText ?? methodInfo.Name
};
Add(button);
return;
Expand All @@ -30,7 +31,7 @@ public MethodButton(object target, MethodInfo methodInfo)

foldout = new Foldout()
{
text = methodInfo.Name,
text = methodInfo.GetCustomAttribute<ButtonAttribute>().LabelText ?? methodInfo.Name,
value = false,
style = {
flexGrow = 1f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public sealed class OrderAttribute : Attribute
}

[AttributeUsage(AttributeTargets.Method)]
public sealed class ButtonAttribute : Attribute { }
public sealed class ButtonAttribute : Attribute
{
public ButtonAttribute() => LabelText = null;
public ButtonAttribute(string labelText) => LabelText = labelText;
public string LabelText { get; }
}

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ShowInInspectorAttribute : Attribute { }
Expand Down

0 comments on commit 879aa3d

Please sign in to comment.