I’m trying to make some custom editors but I’ve just noticed that buttons for some reason seems to tint the background textures when using buttons, I have no idea why this is and on the image attached below it can clearly be seen that the background is white (255,255,255) but the button is (229, 229, 229) BUT both are having the EXACT same background texture
Buttons have some options for state transitions (changing appearance on hover, click, etc. including one for “normal”) and the default setting is a color tint, which is multiplied into the regular color of the Image. Maybe your issue is with that?
There’s also an implicit style set, called a skin, a separate style for button, label, box, etc. By default it uses the currently set GUISkin, which I don’t think is fully opaque, or possibly not completely white.
You can make your own GUISkin asset, then load and use that with GUI.skin = mySkin;
The “LunarisEditorColors.EnumPickerBackgroundTexture” is a plain white texture -
Base64-string: iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=
This same texture is used as background for the dropdown window shown in the bottom of this post, I’ve added it as a background like so:
meanwhile I’m also adding a collection of buttons depending on the amount of enum items:
for (int i = 0; i < enumItems.Count; i++)
{
if (!enumItems[i].name.ToLower().Contains(searchString.ToLower()))
continue;
GUI.backgroundColor = Color.white;
if (GUILayout.Button(enumItems[i].name, (enumItems[i].isSelect ? LunarisEditorStyles.EnumPickerItemSelected : LunarisEditorStyles.EnumPickerItem), GUILayout.Height(20)))
{
if (!allowMultiSelect)
{
if (enumItems.Where(t => t.isSelect).Any())
foreach (var e in enumItems)
e.isSelect = false;
}
enumItems[i].isSelect = !enumItems[i].isSelect;
clicked = true;
}
Rect rect = GUILayoutUtility.GetLastRect();
if (enumItems[i].isSelect)
{
Rect r = GUILayoutUtility.GetLastRect();
GUI.color = Color.green;
r.width = 16;
r.x += 2;
GUI.DrawTexture(r, Resources.Load<Texture2D>("Checkmark"), ScaleMode.ScaleToFit);
GUI.color = Color.white;
}
EditorGUI.DrawRect(rect, new Color(0f, 0f, 0f, 0.1f));
GUILayout.Space(8);
//GUI.DrawTexture(EditorGUILayout.GetControlRect(false, 4), Resources.Load<Texture2D>("ShadowedDivider"), ScaleMode.StretchToFill);
}
Note the line “if (GUILayout.Button(enumItems_.name, (enumItems*.isSelect ? LunarisEditorStyles.EnumPickerItemSelected : LunarisEditorStyles.EnumPickerItem), GUILayout.Height(20)))” and it is using the guistyle “LunarisEditorStyles.EnumPickerItem” which is using the texture “LunarisEditorColors.EnumPickerBackgroundTexture” which is the same I’ve used to set the background texture of the dropdown._
_*_ EDIT: I’ve just tried using guiskin and the result is the exact same, the buttons are tinted for no reason, but other controls generally seems fine.
So while this doesn’t really answer my question and still does make it very tedious to style buttons I found that there is a pretty linenar relation between the actual color value and the “shown” color on the button after trying some different colors and fine tuning it; if I make a texture with the color (67,67,67) the shown value is (60,60,60), the behavior is present if I make an entire white texture, (255,255,255) the actual shown color is (229,229,229) as mention in the first post.
Again this was super tedious and pretty annoying and seems pretty unnecesary (can’t wait till UI element is actually getting better and more useful) but following the graph below seems to give me the correct values Y for a give target value X
Well it’s hard to tell from the given information. However things you want to check are:
What color space is that texture in or was imported in? This might be a gamma correction issue.
It’s about 10 % darker. Are you sure that all colors involved (texture pixels as well as tint colors) are 100% opaque? So they don’t have any alpha value smaller than 255 or 1.0f?
ps: You draw a black rectangle with 10% opacity:
EditorGUI.DrawRect(rect, new Color(0f, 0f, 0f, 0.1f));
So are you sure that’s not your issue? It would match your 10% darkening -.-
Nah, we’re all just working with more and more complex APIs and as a consequence they just have all the more ways to be misused. Glad you’re sparkly white now!