8
\$\begingroup\$

What I would like to know is if there is a easy way using OnInspectorGUI, to replace the inspector with one that includes just one or two additional fields (so that it looks identical to the non-custom editor, except for the addition of one or two fields at the end). It seems like such a bother to recreate every field manually when I just want to add one little thing - so perhaps this is already a thing.

Or is there any way to easily tell unity to do it's default drawing for a specific type of field? When I was playing with this before, I had to commit to exactly what was to be shown, and I would need to manually write each field out --- which is bothersome if the public fields in my class(s) change - and they do frequently during development.

tl;dr - is there any way to simulate the default behavior of the inspector in a custom editor?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

Call this function from inside OnInspectorGUI method to draw the automatic inspector. It is useful you don't want to redo the entire inspector, but you want to add a few buttons to it.

http://docs.unity3d.com/ScriptReference/Editor.DrawDefaultInspector.html

// This example shows a custom inspector for an
// object "MyPlayer", which has a variable speed.
using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(MyPlayer))]
public class Example : Editor
{
    public override void OnInspectorGUI()
    {
        MyPlayer targetPlayer = (MyPlayer)target;
        EditorGUILayout.LabelField ("Some help", "Some other text");

        targetPlayer.speed = EditorGUILayout.Slider ("Speed", targetPlayer.speed, 0, 100);

        // Show default inspector property editor
        DrawDefaultInspector ();
    }
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .