I call the following during OnSceneGui in my custom editor to draw a custom selection box. Everything works as it should, as far as the debugger tells me - the proportions and position of the rectangle are correct, and are adjusted as you’d expect when the mouse moves, but the rectangle will not draw. What am I getting wrong?
Rect boundingRect = new Rect(0,0,0,0);
void CheckForBoundingBox()
{
Event e = Event.current;
HandleUtility.AddDefaultControl( GUIUtility.GetControlID( FocusType.Passive ) );
if( e.button == 0 )
{
if( boundingRect.min != Vector2.zero )
{
boundingRect.size = e.mousePosition - boundingRect.min;
EditorGUI.DrawRect( boundingRect, Color.red );
Debug.Log( "Dragging continues "+boundingRect );
}
if( e.type == EventType.MouseUp )
{
e.Use();
Debug.Log( "Dragging stopped" );
boundingRect.min = Vector2.zero;
}
else if( e.type == EventType.MouseDown )
{
e.Use();
boundingRect.min = e.mousePosition;
boundingRect.size = Vector2.zero;
Debug.Log( "Dragging started" );
}
}
}