x


Managing GUI.depth for drawing lines in EditorWindow

Hello,

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...

more ▼

asked Feb 07 '12 at 11:12 AM

ellolo gravatar image

ellolo
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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:

public void OnGUI () 
{
    // Display links - they appear behind the panels
    foreach( EditorLink link in maLinks )
    {  
       link.DrawLink();
    }

    // Display panels
    BeginWindows();
    for( int i = 0; i < maPanels.Length; i++ )
    {
       EditorPanel panel = maPanels[i] as EditorPanel;
       panel.mWindowRect = GUI.Window( iID, panel.mWindowRect, DoPanelWindow, strTitle );
    }
    EndWindows();
}

I just made a quick test what happens when we draw the lines after EndWindows() :

public void OnGUI () 
{   
    // Display panels
    BeginWindows();
    for( int i = 0; i < maPanels.Length; i++ )
    {
       EditorPanel panel = maPanels[i] as EditorPanel;
       panel.mWindowRect = GUI.Window( iID, panel.mWindowRect, DoPanelWindow, strTitle );
    }
    EndWindows();

    // Display links - they appear in front of the panels
    foreach( EditorLink link in maLinks )
    {  
       link.DrawLink();
    }
}

In this case, the lines are actually drawn in front of the panels.

more ▼

answered Feb 18 '12 at 03:23 AM

Zogg gravatar image

Zogg
46 1 1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x169
x32
x9
x7

asked: Feb 07 '12 at 11:12 AM

Seen: 956 times

Last Updated: Feb 18 '12 at 03:23 AM