Last active
October 12, 2021 02:51
-
-
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
This file contains 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 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