Search Unity

Set color of buttons for Custom Editor

Discussion in 'Editor & General Support' started by litebox, Feb 12, 2021.

  1. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    Hello, I made Custom Editor Window, which I use in the main Scene View to create Palette of colors:
    upload_2021-2-12_17-22-22.png

    to implement this I use set of Buttons, like this:
    Code (CSharp):
    1. GUI.backgroundColor = color;
    2. GUIStyle s = EditorStyles.miniButton;
    3.  
    4. if (GUILayout.Button("", s))
    5. {}
    6.  
    This works pretty well in the Light Unity Editor, however if I select Dark Unity Editor Scheme, I have this:
    upload_2021-2-12_17-45-59.png

    The question is, how can I setup GUI Style to have clean color for both Schemes?
    Cheers!
     
  2. robojacob2005

    robojacob2005

    Joined:
    Jun 7, 2017
    Posts:
    1
    So it turns out that dividing the desired button color with the theme color will give you the needed input value to prevent the tint on the button.

    After scouring the internet, I found this discussion on how to get the background color in the first place.

    Implementing Can-Baycay's solution to get the color, I was able to color the GUI without any use of hard-coded values.

    Code:

    upload_2024-4-22_17-35-53.png

    Dark theme:

    upload_2024-4-22_17-36-15.png

    Light theme:

    upload_2024-4-22_17-36-38.png

    I'd recommend using nicer colors than what I picked though
     

    Attached Files: