Hi.
I want to highlight the background of a field in my custom editor. This highlight is going to be conditional so it will toggle on and off.
I tried and make it work actually but the way I did it, the field gains an extra border when I apply the highlighted background style so it changes its size. If I keep toggling the highlight condition, it makes every other thing in the editor move up and down.
The thing I noticed is, GUILayout.BeginHorizontal causes this problem. If I pass it a style parameter (even an empty style), it adds an extra border to the horizontal area (wrong). If I call BeginHorizontal without a parameter, the horizontal area comes without an extra border so it’s size is smaller (correct and better).
Here is my example code:
static bool Highlighted;
public override void OnInspectorGUI()
{
Highlighted = GUILayout.Toggle(Highlighted, "highlight?");
GUI.backgroundColor = Highlighted ? Color.green : Color.white;
var HighlightStyle = new GUIStyle { normal = { background = Texture2D.whiteTexture } };
if (Highlighted) GUILayout.BeginHorizontal(HighlightStyle); // with style parameter
else GUILayout.BeginHorizontal(); // no style parameter
GUI.backgroundColor = Color.white;
EditorGUILayout.ColorField(Color.white);
GUILayout.EndHorizontal();
}
