Skip to content

Instantly share code, notes, and snippets.

@MattRix
Last active December 22, 2015 21:48

Revisions

  1. MattRix revised this gist Dec 22, 2015. 1 changed file with 5 additions and 11 deletions.
    16 changes: 5 additions & 11 deletions ObjectInspector.cs
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@

    using UnityEngine;
    using UnityEditor;
    using System.Collections;
    using System.Collections.Generic;
    using System.Reflection;
    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.GetCustomAttributes(typeof(MakeButtonAttribute),true).Length > 0)
    if(meth.Name.ToLower().Contains("_button"))
    {
    buttonMethods.Add(meth);
    }
    @@ -47,7 +47,8 @@ override public void OnInspectorGUI()

    foreach(var meth in buttonMethods)
    {
    if(GUILayout.Button(meth.Name))
    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()
    }
    }
    }







  2. MattRix created this gist May 2, 2015.
    74 changes: 74 additions & 0 deletions ObjectInspector.cs
    Original 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]);
    }
    }
    }