Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Creating a node based Editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by sayezz, May 31, 2011.

  1. sayezz

    sayezz

    Joined:
    Mar 9, 2011
    Posts:
    16
    Hey Guys (and Girls),

    i am working on a node based Editor like Playmaker or uScript. The functionality is an other, but the editor GUI, Layout or how ever you would call it has to be a node based, just like uScript or Playmaker.

    I have maneged to got draggable Rects and would like to connect them with a node. Just like uScript does it.

    Here a Screenshot how it could looks like:


    I do not have any idea how i can draw a line. I found a Script here:
    http://www.unifycommunity.com/wiki/index.php?title=DrawLine

    but it do not work how i would like and it draws a line, not a curve.

    So first, how can i draw a curved line, like in the screenshot.
    Second, how can i make those small circles on my Rects. I mean these "connect"-bubbles.

    i dont know if i have to look at EditorWindow, GUILayout, GUI, GUIUtility, etc...

    i would appriciate any hints and help.
     
    Last edited: Jun 6, 2011
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    The nice thing about editor GUI scripting is that you can use Handles, including DrawBezier.
     
  3. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    I'd pay $100 for a generic node editor. Strumpy could make a few bux by seperating it out of his shader editor :)
     
    subho0406 likes this.
  4. sayezz

    sayezz

    Joined:
    Mar 9, 2011
    Posts:
    16
    DrawBezier sounds nice, but how can i use it in :EditorWindow (OnGUI) and not in :Editor (OnScreenGUI). In onScreenGUI i have Vector3 but onGUI in :EditorWindow i have only Vector2. When i try to use DrawBezier in :EditorWindow i cant see anything :(

    ...
    have found a solution here:

    http://forum.unity3d.com/threads/71979-Drawing-lines-in-the-editor

    Thanks!
     
    Last edited: Jun 6, 2011
  5. Eiznek

    Eiznek

    Joined:
    Jun 9, 2011
    Posts:
    374
    Works in EditorWindows just fine.

    Code (csharp):
    1. void DrawCurves(Rect wr, Rect wr2)
    2.     {
    3.         Color color = new Color(0.4f, 0.4f, 0.5f);
    4.         startPos = new Vector3(wr.x + wr.width, wr.y + 3 + wr.height / 2, 0);
    5.         endPos = new Vector3(wr2.x, wr2.y + wr2.height / 2, 0);
    6.         startTangent = startPos + Vector3.right * 50.0f;
    7.         endTangent = endPos - Vector3.left * 50.0f;
    8.                 Handles.DrawBezier(startPos, endPos, startTangent, endTangent,color, BezierTexture, 5f);
    9.     }
     
  6. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    157
    Sorry for resuscitating an old thread, but this was actually the remark that inspired me to create The Spaghetti Machine.
     
  7. Jakobs

    Jakobs

    Joined:
    Nov 10, 2010
    Posts:
    4
    Dont Work =)
    but i'm modify code for EditorWindow
    Code (csharp):
    1.  
    2. public static void DrawCurves(Rect wr, Rect wr2,Color color)
    3.     {
    4.         Vector3 startPos = new Vector3(wr.x + wr.width, wr.y + 3 + wr.height / 3, 0);
    5.         Vector3 endPos = new Vector3(wr2.x, wr2.y + wr2.height / 2, 0);
    6.         float mnog = Vector3.Distance(startPos,endPos);
    7.         Vector3 startTangent = startPos + Vector3.right * (mnog / 3f) ;
    8.         Vector3 endTangent = endPos + Vector3.left * (mnog / 3f);
    9.         Handles.BeginGUI();
    10.         Handles.DrawBezier(startPos, endPos, startTangent, endTangent,color, null, 3f);
    11.         Handles.EndGUI();
    12.     }
    13.  
    and it's look like this:
    $1365689148-clip-9kb.jpg
     
  8. Burletech

    Burletech

    Joined:
    Jul 1, 2010
    Posts:
    73
    I have to say this is really cool. You never know what kind of idea can be sparked in someone from a small little comment.
     
  9. dormouse

    dormouse

    Joined:
    Mar 1, 2011
    Posts:
    81
    and how to create connection bubbles? any ideas?
     
  10. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    Jakobs, would you mind posting your complete code for what you show in the image clip? I am very interested in getting started making these types of graphs, but I just need jumpstart.

    Thanks

    -Raiden
     
  11. DennisVH

    DennisVH

    Joined:
    Jul 8, 2012
    Posts:
    48
    There's an excellent jumpstart example from unity bootcamp asia at https://gist.github.com/AngryAnt/2935408
     
  12. unimechanic

    unimechanic

    Joined:
    Jan 9, 2013
    Posts:
    155
  13. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206