Search Unity

C# custom inspector "headers"

Discussion in 'Scripting' started by SgtLame, Dec 9, 2019.

  1. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    68
    Hi,
    I tried several things (EditorGUILayout.BeginVertical, EditorGUILayout.Foldout, EditorStyles...), and I can't get the desired effect in my custom inspectors. See screen capture below:
    upload_2019-12-9_9-52-28.png

    I would like to get the same "header" style (on "Materials", "Lighting", "Probes"...), without the foldout function. I just need that flat background, stretching on full inspector width. How can one do that?
     
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
    You'll need to know which GUIStyle is applied to that element, from there you can apply it to your header in a custom inspector. Though I am not entirely sure where you can find that. Maybe you can hack it together by trying an onclick event in the editor that prints out the style and log that to the console, than apply that style to your element?
    https://docs.unity3d.com/ScriptReference/GUISkin.GetStyle.html

    In case you cant find it, there is a scripting reference for it:
    https://docs.unity3d.com/ScriptReference/GUIStyle.html
    you might be able to get a similar style working like that.
     
  3. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,130
    Functionality is from a foldout.
    If you want to draw a colored box, then... draw a colored box

    Heres the default MeshRenderer materials foldout, and a custom inspector with the normal foldout and a colored box.

    To add to the post above, you can get the skin style for foldout using EditorStyles.foldout
     
  4. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    277
    I believe that the GUIStyle you're looking for is called "FoldoutHeader".
     
  5. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
    do you know of a way to list up all these guistyles? @SisusCo
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,831
    They are listed in the docs for a GUISkin, which contains all variants.

    You can also just make a GUISkin in your project folder, then inspect it to see the names.

    EDIT: Correction: I might have that wrong; I just made a GUISkin and don't see Foldout Header in there, but I imagine it should be in the docs for GUIStyles or something related.
     
  7. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,130
  8. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
  9. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    68
    Thanks for your answers! I used EditorStyles.foldoutHeader. The foldout arrow appears, but I'm ok with it.
     
  10. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
    You may be able to hide it from the style, if you can find the right internal property. Though I wouldnt know what its called or even how to find it in the first place.
     
  11. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    277
    Sure. I have my own solution for this, but here is one free tool that can do the same.
     
  12. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
    Nice, it would be very useful if there was a screenshot of this in the documentation for that specific GUISkin though. But that works for me even though the UI is disgustingly looking xD I might do some tinkering on the GUI, but thats a good starting point to find them.
     
  13. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    277
    Agreed, it is quite disgusting indeed, hence the custom solution :p

    Also it can be very useful to have the ability to type in some custom text and have it be drawn using the GUIStyle in question. This can help a lot in figuring out whether styles have word-wrapping or not, how they look without any text etc.
     
  14. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    292
    This sounds like something that should exist on the asset store, I might get on that :D.
    Though with black friday I bought Odin, so I dont have all that much need for it.

    Edit: That being said, I could see a use-case for this. Not the first time I see this question asked.
     
    SisusCo likes this.