I am currently doing a state-machine-like editor like The Spaghetti Machine or PlayMaker. Basically, I would like to display boxes and connect them together to represent a work-flow. In addition I would like to be able to edit interactively the content during play-mode.
I've started my work with EditorWindow where I display draggable windows (using GUI.DragWindow()) connected throw this code to draw Bezier curves.
My problem is related with the depth of the Bezier curves. If you take a look on the pictures for drawing lines, you will see that the Bezier curves remain behind the draggable windows, not in front.
I looked for solutions to cope with depth and found that I should use per-script settings for GUI.depth. But I do not see how I can achieve a drawing system like: one script draws the boxes, another one draws the Bezier curves. I thought that both the scripts could inherit from EditorWindow but I then don't know how to instantiate the script that is not launched by the Unity menu. I also thought that I could make the drawing-lines script inherit from MonoBehavior and tag it as ExecuteInEditMode but its OnGUI method is only called when the user interacted with the GUI. So, how can I manage the depth?! The Spaghetti Machine did an awesome work...
It's actually simpler than you thought: In OnGUI, what's drawn first is behind what's drawn second, except for windows drawn inside the BeginWindows-EndWindows block.
In the Spaghetti Machine, the lines are displayed behind the panels because they are drawn first. Boiled down to what is relevant to your question, the OnGUI method looks like this:
I just made a quick test what happens when we draw the lines after EndWindows() :
In this case, the lines are actually drawn in front of the panels.