Skip to content

Instantly share code, notes, and snippets.

@MattRix
Last active October 12, 2021 02:51
Show Gist options
  • Save MattRix/762975c349e6b2f6e2cb to your computer and use it in GitHub Desktop.
Save MattRix/762975c349e6b2f6e2cb to your computer and use it in GitHub Desktop.
Allows you to use OnInspectorGUI in MonoBehaviour directly, rather than having to create a CustomEditor
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
[CustomEditor (typeof(MonoBehaviour),true)]
[CanEditMultipleObjects]
public class MonoBehaviourInspector : Editor
{
public MethodInfo inspectMeth;
public void OnEnable()
{
inspectMeth = target.GetType().GetMethod("OnInspectorGUI",BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic);
}
override public void OnInspectorGUI()
{
DrawDefaultInspector();
if(inspectMeth != null)
{
foreach(var eachTarget in targets)
{
inspectMeth.Invoke(eachTarget, new object[0]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment