I'm trying to change a button's background color in an EditorWindow. I can change tint using GUI.backgroundColor which seems to AND the color with grey, but I want to change it to an exact color. This is what I'm seeing:
Here's the code:
EditorWindowButtonBackgroundColor.cs
using UnityEngine;
using UnityEditor;
public class EditorWindowButtonBackgroundColor : EditorWindow
{
[MenuItem("Tools/Button Background Color Editor Window")]
private static void OpenWindow()
{
GetWindow<EditorWindowButtonBackgroundColor>("Button Background Color");
}
public void OnGUI()
{
GUIStyle yellowBackgroundStyle = new GUIStyle(GUI.skin.button);
yellowBackgroundStyle.normal.background = MakeBackgroundTexture(10, 10, Color.yellow);
if (GUILayout.Button("GUIStyle Button", yellowBackgroundStyle))
{
Debug.Log("GUIStyle Button");
}
Color originalBackgroundColor = GUI.backgroundColor;
GUI.backgroundColor = Color.yellow;
if (GUILayout.Button("GUI.backgroundColor Button", yellowBackgroundStyle))
{
Debug.Log("GUI.backgroundColor Button");
}
GUI.backgroundColor = originalBackgroundColor;
}
private Texture2D MakeBackgroundTexture(int width, int height, Color color)
{
Color[] pixels = new Color[width * height];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = color;
}
Texture2D backgroundTexture = new Texture2D(width, height);
backgroundTexture.SetPixels(pixels);
backgroundTexture.Apply();
return backgroundTexture;
}
}
I got the code for MakeBackgroundTexture
here:
https://forum.unity.com/threads/giving-unitygui-elements-a-background-color.20510/
As you can see, modifying and applying a GUIStyle is not working for me. Any idea what I'm doing wrong?