How to create a control that allows to select position within a line?

Hey everybody. I’m new to editor scripting and it looks like it’s not well documented. At least I can’t find any information about how to do this.

What I want to do is to create a control that looks like this:
https://s16.postimg.org/kmzeylrrp/GIF.gif

This is how it’s implemented when you edit a 2D polygon collider but I want to have a control like that for my own shape editor thingy. And I don’t really know if it’s possible.

What I want is ability to draw a line and indicate a point on it on mouse move, and if you click that point it passes the coordinates to the script so I can create a new point and draw more lines and so on. Is there a control like that? Is it possible to do at all?

Well, if you’d like it to be like the 2D polygon collider, why not use that?

It has some variables which will be useful for this like points and functions like GetPath.
So you could have an object with a 2D polygon collider and when you edit your custom class, you pass this object the polygon data it needs, edit the data on the 2D Polygon Collider, and when you’re done you retrieve the points variable plus other things you need and use it to form the -now edited- custom class that uses these polygons.

It’s a bit of a hack, if you’re doing it a lot, a custom editor will be the better option. And you’ve already tagged the right class for this: Handles (gizmos is more for in scene view, which could be used for 3D polygons).

Hope this puts you in the right direction,

-Gameplay4all

What you want to do is implement an EditorWindow. From there, you can use the editor graphics calls to generate the lines and nodes. You will most likely have to write all the logic for creation/dragging/etc. yourself, but that will provide a good venue to do so. See here for how to create the Window, and here for how to draw the components.

I’ve figured out how to do this, but maybe I did it the hard way.

Here’s how it looks.

I’m tracking the position of a mouse using custom editor script, calculating where the point should be by comparing bunch of distances and angles and then drawing Handle.Button() at that location. I hope it’s the best way because I’ve spent too much time writing complicated math I don’t understand.