- Home /
Question by
Igor_Vasiak · Nov 30, 2018 at 08:35 PM ·
editoreditor-scriptingcustom editorcustom-inspectorcustomization
Responsive Editor UI Button with custom style | How to remove GUIStyle.hover delay
I'm trying to make magic in Unity and actually create some modern-ish UI for my editors. Something that I never figured out (and that would allow me to make something like Spotify's song selection lists) is how to make a GUI.button change color responsively on hover and click. It always gives me a delay while using GUIStyles. Why is that? Is there a better way of going this route? Here's what I have right now:
Rect test = EditorGUILayout.BeginHorizontal();
test.y -= 8;
test.x -= 14;
test.height = 40;
test.width = Screen.width;
GUIStyle style = new GUIStyle();
Texture2D hover = new Texture2D(1, 1);
hover.SetPixel(0, 0, new Color32(22, 22, 22, 60));
style.hover.background = hover;
style.active.background = null;
style.normal.background = null;
GUI.Button(test, "", style);
Also, how can I change the color of the hover texture? That SetPixel just doesn't cut it! Thanks.
Comment
This is a great question. I tried some of my own code to make the GUI.Button change colors on hover and click. Unfortunately, the color change is delayed for so long as to be totally infuriating
demo.gif
(143.5 kB)