Last active
December 22, 2015 21:48
Revisions
-
MattRix revised this gist
Dec 22, 2015 . 1 changed file with 5 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using UnityEditor; using System.Reflection; [CustomEditor (typeof(UnityEngine.Object),true)] [CanEditMultipleObjects] @@ -26,7 +26,7 @@ public void OnEnable() foreach(var meth in meths) { if(meth.Name.ToLower().Contains("_button")) { buttonMethods.Add(meth); } @@ -47,7 +47,8 @@ override public void OnInspectorGUI() foreach(var meth in buttonMethods) { string methName = meth.Name.Substring(0,meth.Name.ToLower().IndexOf("_button")); if(GUILayout.Button(ObjectNames.NicifyVariableName(methName))) { foreach(var eachTarget in targets) { @@ -65,10 +66,3 @@ public void OnSceneGUI() } } } -
MattRix created this gist
May 2, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; using System.Reflection; using System; [CustomEditor (typeof(UnityEngine.Object),true)] [CanEditMultipleObjects] public class ObjectInspector : Editor { public MethodInfo inspectMeth; public MethodInfo sceneMeth; public List<MethodInfo>buttonMethods = new List<MethodInfo>(); public void OnEnable() { var type = target.GetType(); inspectMeth = target.GetType().GetMethod("OnInspectorGUI",BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic); sceneMeth = target.GetType().GetMethod("OnSceneGUI",BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic); var meths = type.GetMethods(); foreach(var meth in meths) { if(meth.GetCustomAttributes(typeof(MakeButtonAttribute),true).Length > 0) { buttonMethods.Add(meth); } } } override public void OnInspectorGUI() { DrawDefaultInspector(); if(inspectMeth != null) { foreach(var eachTarget in targets) { inspectMeth.Invoke(eachTarget, new object[0]); } } foreach(var meth in buttonMethods) { if(GUILayout.Button(meth.Name)) { foreach(var eachTarget in targets) { meth.Invoke(eachTarget, new object[0]); } } } } public void OnSceneGUI() { if(sceneMeth != null) { sceneMeth.Invoke(target, new object[0]); } } }