mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 16:28:23 -05:00
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using System.Reflection;
|
|
using TriInspector;
|
|
using TriInspector.Drawers;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[assembly: RegisterTriAttributeDrawer(typeof(ButtonDrawer), TriDrawerOrder.Drawer)]
|
|
|
|
namespace TriInspector.Drawers
|
|
{
|
|
public class ButtonDrawer : TriAttributeDrawer<ButtonAttribute>
|
|
{
|
|
public override float GetHeight(float width, TriProperty property, TriElement next)
|
|
{
|
|
return EditorGUIUtility.singleLineHeight;
|
|
}
|
|
|
|
public override void OnGUI(Rect position, TriProperty property, TriElement next)
|
|
{
|
|
var name = Attribute.Name ?? property.DisplayName;
|
|
|
|
if (GUI.Button(position, name))
|
|
{
|
|
var methodInfo = (MethodInfo) property.MemberInfo;
|
|
|
|
for (var i = 0; i < property.PropertyTree.TargetObjects.Length; i++)
|
|
{
|
|
var parentValue = property.Parent.GetValue(i);
|
|
methodInfo.Invoke(parentValue, new object[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |