Add: LabelText argument for Button attribute

This commit is contained in:
yuyu0127 2024-03-17 00:22:12 +09:00 committed by yuyu0217
parent bcaeef5ea9
commit 879aa3db25
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System.Reflection;
using Alchemy.Inspector;
using UnityEditor;
using UnityEngine.UIElements;
@ -17,7 +18,7 @@ namespace Alchemy.Editor.Elements
{
button = new Button(() => methodInfo.Invoke(target, null))
{
text = methodInfo.Name
text = methodInfo.GetCustomAttribute<ButtonAttribute>().LabelText ?? methodInfo.Name
};
Add(button);
return;
@ -30,7 +31,7 @@ namespace Alchemy.Editor.Elements
foldout = new Foldout()
{
text = methodInfo.Name,
text = methodInfo.GetCustomAttribute<ButtonAttribute>().LabelText ?? methodInfo.Name,
value = false,
style = {
flexGrow = 1f

View File

@ -18,7 +18,12 @@ namespace Alchemy.Inspector
}
[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 { }