Search Unity

Question DrawDefaultInspector on AudioSource not drawing the default Inspector.

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

  1. phoenix0330

    phoenix0330

    Joined:
    Dec 4, 2010
    Posts:
    65
    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 =>
    upload_2022-8-25_12-57-49.png

    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.

    upload_2022-8-25_13-13-32.png
    is there a way to show the properties like the first image ?
    thanks

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