I'm trying to make a button wrapper class that easily allows for mouseover detection. I it working for regular GUI.Buttons, but now I'd like to make it compatible with GUILayout.Buttons, as well. The problem is that I don't have direct access to the Rect of a GUILayout.Button.
I understand that I can use GUILayoutUtility.GetLastRect to get the last drawn rectangle, but doesn't this mean that I can only do one button at a time? I don't understand how I would go about referencing the rects of multiple buttons this way.
You can use GetLastRect to find the area of a group of controls if the controls are wrapped in Begin/EndVertical or Begin/EndHorizontal, like so:
if(Event.current.type == EventType.Repaint &&
GUILayout.Label( "Mouse over!" );
GUILayout.Label( "Mouse somewhere else" );
Alternatively you could use GUILayout.BeginArea to confine the auto-layout to a fixed area of the screen that you control.