Search Unity

Question Text colors dont change if I set a background texture in style and other issues

Discussion in 'Immediate Mode GUI (IMGUI)' started by SpookyCat, Apr 30, 2023.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    I am trying to recreate the Hierarchy window for a custom EditorWindow I am working on. I have it displaying and I am using EditorStyles.foldoutHeader for parent objects so it shows the > arrow, I cant seem to find an EditorStyle that has the down arrow for when it is expanded, so I am trying to add my own styles using the foldoutheader style as the base.

    So I create a new style based on the old one, and if I dont change anything it works just the same. I then change the various colors for hover etc and that works fine as well. But if I set a new background texture in the hover style then I can see the texture but now the colors dont change.

    Also if I change the texture how does that work with the dark and light themes?

    This is the code to make the new style:
    Code (CSharp):
    1.             if ( text == null )
    2.                 text = new Texture2D(1, 1);
    3.  
    4.             buttonStyle = new GUIStyle(EditorStyles.foldoutHeader);
    5.             buttonStyle.normal.textColor = Color.blue;
    6.             buttonStyle.onNormal.textColor = Color.white;
    7.             buttonStyle.onHover.textColor = Color.black;
    8.             buttonStyle.hover.textColor = Color.cyan;
    9.             buttonStyle.onActive.textColor = Color.green;
    10.             buttonStyle.onFocused.textColor = Color.red;
    11.             buttonStyle.normal.background = text;
    12.  
    And here is the result without setting the background texture, you can see the colours are changing:
    Screenshot 2023-04-30 183615.png
    And the same when I set the background texture, colours are all the same:
    Screenshot 2023-04-30 183637.png