- Home /
Get position of Rect in Rect in EditorWindow
I have a problem getting the position of a Rect inside my EditorWindow:
I'm working on a node based editor, so in a new EditorWindow I create a node with myWindow = GUILayout.Window(windowID, myWindow, DrawNodeWindow, myName);
and the setup for the node is in here (minimal example)
void DrawNodeWindow(int id)
{
//some Layout stuff
if (GUILayout.Button("", EditorStyles.radioButton, GUILayout.Width(16), GUILayout.Height(16)))
{
//draw a line beginning in the center of this button
Rect myRect = GUILayoutUtility.GetLastRect();
}
//More layout stuff
}
Now I want to draw a line from one nodeWindow to an other. For this I need the center of the radioButton I created.
So I get the Rect of the button with GetLastRect(). I already checked if I got this right by using EditorGUI.DrawRect(myRect, color.black) and there is a black Rect over my button, just where I need it.
Now I can't get the position of myRect.
MyRect.position is somehow always 0,0. It seems I would need to add the position of all the other Rects it is in to it (like the position of the window for example) but the problem is I use lots of autolayout stuff like Beginhorizontal nested in a BeginVertikal and so on. So I don't really know how many Rects there are.
I simply need the position of the Rect in my EditorWindow.
Answer by suchoparek · Jun 01, 2016 at 06:06 AM
@somethingwithcode As you know the myWindow Rect original position, you could just sum up that one with myRect local position to obtain the absolute position. Something like this:
Vector3 myRectPos= myWindow.position + GUILayoutUtility.GetLastRect().position;
Your answer
Follow this Question
Related Questions
Small GUILayout button 1 Answer
Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer
Positioning a button at the bottom of an editor window 1 Answer
Drag a non standard unity asset on a custom editor slot 1 Answer
Custom Editor Struct array layout 0 Answers