Probably a simple question for people who have experience with editorWindows.
I can’t seem to fetch the position of the mouse when it goes outside the editorWindow, no MouseMove events are send to the window anymore.
It should be possible though, because other tools are able to do it.
2 Answers
2
Indeed, the mouse position does get lost when it leaves the window. You could probably poll Event.current.mousePosition for the current position (Vector2). All that would be needed then is to compare it to the previous values to determine how much it has moved.
Found a smooth solution for my particular problem.
public void Update()
{
if (getMouseOutsideWindow){
Repaint ();
}
}
Calling repaint in the update function, makes OnGUI() getting called each frame. (Before, OnGUI() only got called when the mouse was over the window.) So now I can get the mousePosition in OnGUI, even from out the window.
If people want events from outside the window, this should be used in combination with Event.rawType. (Or directly in Update() instead of OnGUI().)
The problem is, the values for Event.current.mousePosition aren't update anymore as soon as I leave the window. But perhaps that's because OnGUI() doesn't get called anymore.. I'm getting an idea here, maybe I should poll for the mouseposition in the Update() method.
– Unitraxx