Drawing lines in editor GUI? [SOLVED]

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

You can use this script on the wiki.

--Eric

Thanks!

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

the animation editor uses the curve related stuff. You can look that up

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)?

Are you changing the GUI matrix elsewhere in your script? Please post the script here if possible.

Copied the DrawLine script from the wiki, then from my otherwise empty class tried now to translate Js mousefollow script to C#:

  void OnGUI(){
        Vector2 pointA = new Vector2(Screen.width / 2, Screen.height / 2);
        Vector2 pointB = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
        Drawing.DrawLine(pointA, pointB, Color.red, 2);

        //Drawing.DrawLine(new Vector2(0, 0), new Vector2(200, 200), Color.red, 2); 
    }

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.

Update to the suggested link above (since Unity wiki has moved):
http://wiki.unity3d.com/index.php/DrawLine

[quote=“cgiguy”, post:8, topic: 412681]
Update to the suggested link above (since Unity wiki has moved):
http://wiki.unity3d.com/index.php/DrawLine
[/quote]
This link seems to be dead