Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question DrawDefaultInspector on AudioSource not drawing the default Inspector.

Discussion in 'Immediate Mode GUI (IMGUI)' started by phoenix0330, Aug 25, 2022.

  1. phoenix0330


    Dec 4, 2010
    Hi, i need a little help with this task.
    i need to change between hide properties of the AudioSource component on the inspector and show original properties. This are the original properties =>

    But, when i tried to add a custom editor to show/hide properties, the options shown with DrawDefaultInspector() are way to different from the ones before.

    is there a way to show the properties like the first image ?

    Code (CSharp):
    1. [CustomEditor(typeof(AudioSource))]
    2. public class HideAudioSource : Editor
    3. {
    4.     public static HideAudioSource instance;
    5.     public bool hideOptions = true;
    7.     private void OnEnable()
    8.     {
    9.         instance = this;
    10.     }
    12.     public override void OnInspectorGUI()
    13.     {
    14.         AudioSource myTarget = (AudioSource)target;
    16.         if (!hideOptions)
    17.             DrawDefaultInspector();
    18.     }
    19. }