Editor GUI Drag Selection Box

I’m working on a script where you would drag a selection box around textures in an editor window.

The concept I’m working with is to check for a mouse drag event, record the mouse position on start drag, and draw a texture with one corner at the start drag coordinates and the other corner at the current mouse position.

It seems that OnGUI doesn’t update enough to draw a draggable selection box like this. What do you think is the most efficient way to tackle this problem?

Edit:
Here is the code I’m using

private bool isDragging = false;
Vector2 mouseDragStart;
...
void OnGUI() {
if(Event.current.type == EventType.mouseDrag) {
	if(!isDragging) { 
		mouseDragStart = Event.current.mousePosition;
		isDragging = true;
	}
}
if(Event.current.type == EventType.mouseUp && isDragging) isDragging = false;
GUI.Box (new Rect(mouseDragStart.x,mouseDragStart.y,100f,100f),"test"); // testing, box moving with mouse drag
}

It looks to me like you aren’t updating the mouse position you draw at unless isDragging = false! I don’t think that’s what you meant.

Presumably you want to draw the box from mouseDragStart to the current mouse position.

That would have your last line as:

 if(Event.current.type==EventType.mouseDrag) {
    currentMousePosition = Event.current.mousePosition;
  
}
  GUI.Box(new Rect(mouseDragStart.x, mouseDragStart.y, currentMousePosition.x, currentMousePosition.y), "test");

And add a class level variable called currentMousePosition : Vector2

EDIT

The problem was more complicated than this first solution suggests. When writing an EditorWindow that reacts to mouse events you should make sure that it has its wantsMouseMove = true and then you should consume the events that you use, which makes Unity send them to you more frequently. To use an event you do something like this:

var e = Event.current;
if(e.isMouse)
{
    e.Use();
}