Created
August 1, 2024 01:05
-
-
Save mashlol/92e66afb616ee2f1c66158cf0c2c8280 to your computer and use it in GitHub Desktop.
Super Simple Unity Editor Button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] | |
public class ButtonAttribute : Attribute {} | |
[CustomEditor(typeof(UnityEngine.Object), true)] | |
[CanEditMultipleObjects] | |
public class BetterObjectEditor : Editor { | |
public override void OnInspectorGUI() { | |
DrawDefaultInspector(); | |
var methods = target.GetType().GetMethods( | |
BindingFlags.Instance | | |
BindingFlags.Static | | |
BindingFlags.Public | | |
BindingFlags.NonPublic | |
); | |
foreach (MethodInfo method in methods) { | |
if (method.GetCustomAttribute<ButtonAttribute>() == null) | |
continue; | |
if (GUILayout.Button(method.Name)) | |
method.Invoke(target, new object[0]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: