- Home /
GUI.Window called 2 frames ahead than OnGUI?
When modifying window rect for same amount before and after gui.window call:
Vector2 mousePosition = Event.current.mousePosition;
rect.position -= mousePosition;
rect = GUILayout.Window (0, rect, DrawWindow, "bla");
rect.position += mousePosition;
rect is not drawn properly in GUILayout.Window or GUI.Window, it moves as if I was feeding -Event.current.delta/2f
to it (and if I add it back it stays still but looks glithy, so I have to round values which is a mess).
Seems to me like gui.window is called frame after even tho if I drag the window, rect before will not be the same as rect after inside the scope which is expected.
So, rect.position before addition and after subtraction is same, but rect is not drawn where it should be in gui.window, it moves dependently of mousePosition since that value is changing between frames.
I have stored the mouse position of second last frame and it works but it makes a lot of new problems that are hard to track. How can this be done without assigning past values?
Thanks!
What are you trying to achieve in the end? Dragging or resizing the window?
I implemented offset and scaling, but the values jump like crazy while its visually ok. I'd like to understand what is happening so I can write clean code.
Not sure if this helps anything, but maybe you could try something like this? Because this is currently executed at least 2 times per frame, and maybe more depending on mousemove, keypress etc. (If this doesn't help then I don't know what the problem could be :p)
if (Event.current.type == EventType.Layout)
{
rect.position -= mousePosition;
}
rect = GUILayout.Window(0, rect, DrawWindow, "bla");
if (Event.current.type == EventType.Layout)
{
rect.position += mousePosition;
}
Your answer
Follow this Question
Related Questions
GUILayout three buttons alligned horizontally with no spaces between them 1 Answer
rotate a single GUI element around pivotPoint 0 Answers
Get Mouse Events with EditorWindow 3 Answers
How do i get size in pixels of a GUI.Label for chat construction purpose ? 2 Answers
Can not close editor window not in GUILayout.somemethod in OnGUI method 0 Answers