Hi, Im writing a onscenegui polygon editor, trying to mimic the polygoncollider2D editor. I am using a FreeMoveHandle for each vertex (green) and there is a dotcap handle (shown in cyan) to show where new vertices would be placed
A new vertex is placed when the cyan dotcap handle is visible and the mouse button is clicked. This means i have to click to place, then click to drag the FreeMoveHandle of the new vertex.
This is pretty cumbersome and I really would like to just click and drag. Does anyone know how i could achieve this?
The code to add a new vertex is as follows;
Handles.color = Color.cyan;
Vector3 closestPoint = HandleUtility.ClosestPointToPolyLine(polygonArray);
Handles.DotCap(0,closestPoint,Quaternion.identity,handleSize);
if(e.type == EventType.mouseDown && e.button == 0)
{
AddPoint(closestPoint);
}
Handles.color = Color.green;
and
private void AddPoint(Vector3 pointToAdd)
{
m_PointCount.intValue++;
int[] polygonEdge = FindEdgeByPoint(pointToAdd);
for(int i = m_PointCount.intValue-2 ; i >= polygonEdge[1] ;i--)
{
SetPointArray(i+1, GetPointAtIndex(i));
}
SetPointArray(polygonEdge[1], pointToAdd);
}