First, some foundation for the question. In my EditorWindow
I have a Scroll View created with EditorGUILayout.BeginScrollView/EndScrollView
. I then use the Rect created there to similarly position a Group, created with GUI.BeginGroup
. Inside of that I do a whole bunch of custom drawing including some standard GUI fields, passing them custom Rects.
I have my own system of selection, which includes drawing a selection box when the mouse is dragged over that content Group. Everything works like a charm except detecting MouseUp events when outside of the editor window.
The main Unity Scene does precisely this so I know that it’s possible. The only question is how is it done?
This does appear to be a fairly common question, and only one viable solution appears to exist as I understand it. That solution does not work for me, however.
The solution linked above appears to require the use of GUI.hotControl
to be set to something that receives mouseUp events (with the correct FocusType set?). But I do not have a control to focus anyway: Groups/Scroll Views appear to never take “focus”. When I detect the right situation in my GUI, I clear the focus entirely using GUI.FocusControl("")
. This leaves me to handle the mouse events as I see fit.
When the mouse is over the EditorWindow
, this works flawlessly. When I drag to a position outside of the window, however, I continue to get events with type EventType.MouseDrag
until I release the mouse button. (I get events by calling Repaint()
in Update()
when I have an active selection box). When I release the button, I stop getting updates entirely.
This means that I never get the MouseUp
event and I only start getting MouseMove
events again once the mouse is actually over the EditorWindow
. This happens even when I force a Repaint()
for every call to Update()
.
According to everything I’ve seen and my own personal tests with Unity-provided controls (TextField
s, for instance), I simply never get those events (e.g. when dragging a selection over some text in a test TextField
, the event flow is identical to what I described above).
For the time being, I now have the selection disappearing when an active selection exists and MouseMove
event is encountered. This clears the selection once the user hovers over the window again. Far less than ideal, but workable.
How do I make sure these events reach my EditorWindow
?
The main Scene View appears to be able to handle these events and certain documentation makes it seem viable. What is the magic sauce?
Edit: I’m running Unity 4.5.4f1 on Mac OSX.