I've got a simple question. I would like to open an editor window in unity and have it's top left corner be at the cursor's position. I have tried setting EditorWindow.position to Event.current.mousePosition but this has yielded no results.
It seems that Event.current.mousePosition has it's origin at the top left of whatever window it was last in (inspector, etc.).
Any help?
You could approach it like this (tested, works):
public class MyWindow : EditorWindow
{
bool initializedPosition = false;
...
void OnGUI()
{
if (!initializedPosition)
{
Vector2 mousePos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
position = new Rect(mousePos.x, mousePos.y, position.width, position.height);
initializedPosition = true;
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With