Search Unity

Editor: Trying to duplicate Unity's Settings Gear icon with dropdown arrow in custom window

Discussion in 'Immediate Mode GUI (IMGUI)' started by jwvanderbeck, Jan 30, 2018.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Hey all,
    I am trying to duplicate the appearance of the standard Unity Settings Icon that appears to the right of each component in the inspector. It is a small gear with an arrow next to it. I would imagine there is a proper built in editor style that matches this but I just can't seem to find it!

    Any tips? I can get pretty close but not xact, and I really want exact to provide a cohesive artist experience.

    Code (CSharp):
    1. EditorGUILayout.DropdownButton(EditoGUIUtilty.IconContent("SettingsIcon"), FocusType.Passive, EditorStyles.????);
     
    simonpasi_XR likes this.
  2. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
  3. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    Hi,

    You can do it like this:
    Code (CSharp):
    1.  
    2.         GUIStyle iconButtonStyle = GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton");
    3.         GUIContent content = new GUIContent(EditorGUIUtility.Load("icons/d__Popup.png") as Texture2D);
    4.         if (EditorGUILayout.DropdownButton( content, FocusType.Passive, iconButtonStyle))
    5.         {
    6.              
    7.         }
    8.  
    Enjoy :)
     
    MrSIiddes, simonpasi_XR and TonyLi like this.
  4. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Thanks! That is perfect. For the dark skin. Do you know the change to make to get a version for the light skin as well? Some artists here use both.
     
  5. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Found it. "icons/_Popup.png"
     
    simonpasi_XR likes this.
  6. CrystalConflux

    CrystalConflux

    Joined:
    May 25, 2017
    Posts:
    107
    For future reference,

    Code (CSharp):
    1. GUIContent popupIcon = EditorGUIUtility.IconContent("_Popup");
    Will also work to get the icon, and will automatically adjust for dark theme if necessary.


     
  7. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    This doesn't seem to work for me. It returns the black version on the dark theme when I would expect the grey version. Is there something above this I am missing to enable the auto adjust feature?
     
  8. CrystalConflux

    CrystalConflux

    Joined:
    May 25, 2017
    Posts:
    107
    Hmmm. Are you sure you're using the correct icon when making the button? What Unity version are you on? It works for me in Unity 2018 anyway, and I'm using dark mode (also tested light mode).

    The full code I used to make the button:
    Code (CSharp):
    1. var popupStyle = GUI.skin.FindStyle("IconButton");
    2. var popupIcon = EditorGUIUtility.IconContent("_Popup");
    3. var buttonRect = EditorGUILayout.GetControlRect(false, 20f, GUILayout.MaxWidth(20f));
    4. if (GUI.Button(buttonRect, popupIcon, popupStyle))
    5. {
    6.     //Stuff that happens when you click the button
    7. }

    It also worked using a EditorGUILayout.DropdownButton when I tried it.
     
    vedram likes this.
  9. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    I'm doing much the same, though using GUILayout rather than handle the rects myself. The only real difference is I am getting the IconButton skin from the Inspector skin, but I tried it your way with the same result.

    Full dropdowns do look correct per skin. It's just this icon by itself that I want does not.

    Unity 2018.3

    Code (CSharp):
    1. GUIStyle iconButtonStyle = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton");
    2. GUIContent moveGroupButton = EditorGUIUtility.IconContent("_Popup");
    3. // ...
    4. if (GUILayout.Button(moveGroupButton, iconButtonStyle))
    5. {
    6. //
    7. }
    8.  
     
  10. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Hah nevermind. Error was all mine. Found an errant call that was actually setting the GUI.color to black!
     
    CrystalConflux likes this.
  11. CrystalConflux

    CrystalConflux

    Joined:
    May 25, 2017
    Posts:
    107
    Ah, I see. Classic. :D