Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Drawing lines in editor GUI? [SOLVED]

Discussion in 'Extensions & OnGUI' started by invicticide, Apr 29, 2010.

  1. invicticide

    invicticide

    Joined:
    Nov 15, 2009
    Posts:
    108
    Looking through the script reference, I can see how to draw a line in the 3D scene view, but what if I have a custom EditorWindow and I want to draw some 2D lines in that? Like the interface you see in the built-in animation editor, for example?

    Am I just totally blind? I can't find any functions for that. :(
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,935
    You can use this script on the wiki.

    --Eric
     
  3. invicticide

    invicticide

    Joined:
    Nov 15, 2009
    Posts:
    108
    Thanks!

    There is something sublimely hilarious about the fact that this particular implementation is actually necessary... but I'll run with it. :D
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,600
    the animation editor uses the curve related stuff. You can look that up
     
  5. kelmer

    kelmer

    Joined:
    Jun 18, 2010
    Posts:
    24
    Hi all,

    I tried this snippet of code, but it doesn't seem to be working properly for me, if I set vectorA to (0,0) and vectorB to (100, 100) the line starts at the left side of the screen, but on an arbitrary Y-axis point. Like, maybe at the (0,100) with 0,0 being the top left.


    If I set vectorB to (200, 200) then, the arbitrary Y-axis point is drawn closer to the bottom.

    Maybe I'm getting this wrong, but if vectorA is the same on both cases, shouldn't it always start at the (0,0) position (top left)?
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Are you changing the GUI matrix elsewhere in your script? Please post the script here if possible.
     
  7. kelmer

    kelmer

    Joined:
    Jun 18, 2010
    Posts:
    24
    Copied the DrawLine script from the wiki, then from my otherwise empty class tried now to translate Js mousefollow script to C#:

    Code (csharp):
    1.   void OnGUI(){
    2.         Vector2 pointA = new Vector2(Screen.width / 2, Screen.height / 2);
    3.         Vector2 pointB = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
    4.         Drawing.DrawLine(pointA, pointB, Color.red, 2);
    5.  
    6.         //Drawing.DrawLine(new Vector2(0, 0), new Vector2(200, 200), Color.red, 2);
    7.     }

    Point A does not stay at the center but keeps moving.

    The commented line below was my previous attempt to draw lines from 0,0.
     
  8. cgiguy

    cgiguy

    Joined:
    Jan 21, 2010
    Posts:
    4