38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
using System.Linq;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace CustomAttributes
|
|||
|
{
|
|||
|
[CustomEditor(typeof(object), true, isFallback = false)]
|
|||
|
[CanEditMultipleObjects]
|
|||
|
public class ButtonEditor : Editor
|
|||
|
{
|
|||
|
public override void OnInspectorGUI()
|
|||
|
{
|
|||
|
base.OnInspectorGUI();
|
|||
|
|
|||
|
foreach(var target in targets)
|
|||
|
{
|
|||
|
var mis = target.GetType().GetMethods().Where(m => m.GetCustomAttributes().Any(a => a.GetType() == typeof(EditorButtonAttribute)));
|
|||
|
if(mis != null)
|
|||
|
{
|
|||
|
foreach(var mi in mis)
|
|||
|
{
|
|||
|
if(mi != null)
|
|||
|
{
|
|||
|
var attribute = (EditorButtonAttribute)mi.GetCustomAttribute(typeof(EditorButtonAttribute));
|
|||
|
if (GUILayout.Button(attribute.name))
|
|||
|
{
|
|||
|
mi.Invoke(target, null);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|