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
}