The DrawDefaultInspector Function

Checked with version: 4.3

-

Difficulty: Intermediate

The DrawDefaultInspector function allows us to easily recreate the default inspector for a script inside a custom inspector. This is very useful if we only want to add new items to the inspector for a script instead of changing the currently existing items. In this video you will learn how to use the DrawDefaultInspector function.

The DrawDefaultInspector Function

Intermediate Interface & Essentials

SomeScript

Code snippet

using UnityEngine;
using System.Collections;
using UnityEditor;

public class SomeScript : MonoBehaviour 
{
    public int level;
    public float health;
    public Vector3 target;
}
#pragma strict

var level : int;
var health : float;
var target : Vector3;
import UnityEngine
import System.Collections
import UnityEditor


public class SomeScript(MonoBehaviour):

    public level as int

    public health as single

    public target as Vector3

SomeScriptEditor

Code snippet

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(SomeScript))]
public class SomeScriptEditor : Editor 
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.HelpBox("This is a help box", MessageType.Info);
    }
}
#pragma strict

@CustomEditor (SomeScript)
public class SomeScriptEditor extends Editor 
{
    function OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.HelpBox("This is a help box", MessageType.Info);
    }
}
import UnityEngine
import System.Collections
import UnityEditor


[CustomEditor(typeof(SomeScript))]
public class SomeScriptEditor(Editor):

    public override def OnInspectorGUI():
        DrawDefaultInspector()
        
        EditorGUILayout.HelpBox('This is a help box', MessageType.Info)

Related tutorials