private void  ShowPointControls(Ferr2DPath aPath, int i, PathEditorUtil.Selection aSelection, Matrix4x4 aTransform, SerializedProperty aPathProp)
    {
        EventType eType = Event.current.type;

        Ferr2D_PointData pointData        = aPath.GetData(i);
        Vector2          point            = aPath[i];
        Vector2          pointNormal      = aPath.GetNormal(i);
        Vector3          pointWorld       = aTransform.MultiplyPoint(point);
        Vector3          pointWorldNormal = aTransform.MultiplyVector(pointNormal);
        float            pointSize        = eType == EventType.Layout || eType == EventType.Repaint ? HandleUtility.GetHandleSize(pointWorld) : 0;

        // point scale button
        if (terrain.EdgeMode != Ferr2D_SectionMode.None && (i == activePoint || aSelection.IsSelected(i) || pointData.scale != 1))
        {
            Vector3 scaleStart = pointWorld + pointWorldNormal * (visuals.sizeVertex + sizeSmallHandle) * pointSize;
            Vector3 scalePos   = scaleStart + ((pointData.scale - 0.5f) * 3f) * pointWorldNormal;
            if (Event.current.alt)
            {
                // reset scale
                if (pointData.scale != 1 && Handles.Button(scalePos, Quaternion.identity, pointSize * sizeSmallHandle, pointSize * sizeSmallHandle, Ferr2DT_Caps.CapDotReset))
                {
                    aSelection.Each(i, id => {
                        SerializedProperty scaleProp = aPathProp.FindPropertyRelative("_data").GetArrayElementAtIndex(id).FindPropertyRelative("scale");
                        scaleProp.floatValue         = 1;
                    });
                }
            }
            else
            {
                Vector2 screenNormal = HandleUtility.WorldToGUIPoint(pointWorld + pointWorldNormal) - HandleUtility.WorldToGUIPoint(pointWorld);
                screenNormal.Normalize();

                Vector3 move = Handles.FreeMoveHandle(scalePos, Quaternion.identity, pointSize * sizeSmallHandle, Vector3.zero, Ferr2DT_Caps.GetScaleCap(screenNormal));
                if (move != scalePos)
                {
                    move = PathUtil.GetClosetPointOnLine(scaleStart, scaleStart + pointWorldNormal * 3, move, true);
                    float finalScale = 0.5f + (scaleStart - move).magnitude / 3f;
                    float delta      = finalScale - pointData.scale;

                    aSelection.Each(i, id => {
                        SerializedProperty scaleProp = aPathProp.FindPropertyRelative("_data").GetArrayElementAtIndex(id).FindPropertyRelative("scale");
                        scaleProp.floatValue        += delta;
                    });
                }
            }
        }

        // show index numbers
        if (Ferr2DT_SceneOverlay.showIndices)
        {
            Vector2 pt = HandleUtility.WorldToGUIPoint(pointWorld - pointWorldNormal * pointSize * sizeLargeHandle * 2);
            Rect    r  = new Rect(pt.x - 15, pt.y - EditorGUIUtility.singleLineHeight * 0.5f, 30, EditorGUIUtility.singleLineHeight);
            Handles.BeginGUI();
            GUI.Label(r, i.ToString(), PathEditorUtil.CenteredShadowStyle);
            GUI.Label(r, i.ToString(), PathEditorUtil.CenteredLabelStyle);
            Handles.EndGUI();
        }
    }
    public void LegacyUpgrade()
    {
        if (!IsLegacy)
        {
            return;
        }

                #if UNITY_EDITOR
        UnityEditor.Undo.RecordObject(gameObject, "Upgrade Ferr2D Terrain");
                #endif

        Ferr2D_Path oldPath = GetComponent <Ferr2D_Path>();
        MatchOverrides();

        // upgrade the path
        pathData        = new Ferr2DPath();
        pathData.Closed = oldPath.closed;
        for (int i = 0; i < oldPath.pathVerts.Count; i++)
        {
            int            next      = Ferr.PathUtil.WrapIndex(i - 1, Path.Count, Path.closed);
            Ferr.PointType pointType = Ferr.PointType.Sharp;
            if (smoothPath)
            {
                Ferr2DT_TerrainDirection prevSegmentDirection = Ferr2D_Path.GetDirection(Path.pathVerts, next, fill == Ferr2DT_FillMode.InvertedClosed, Path.closed, directionOverrides);
                Ferr2DT_TerrainDirection nextSegmentDirection = Ferr2D_Path.GetDirection(Path.pathVerts, i, fill == Ferr2DT_FillMode.InvertedClosed, Path.closed, directionOverrides);
                if (prevSegmentDirection == nextSegmentDirection)
                {
                    pointType = Ferr.PointType.Auto;
                }
            }

            Ferr2D_PointData data = new Ferr2D_PointData();
            data.scale             = vertScales[next];
            data.directionOverride = (int)directionOverrides[next];
            data.cutOverrides      = cutOverrides[next].data;
            pathData.Add(oldPath.pathVerts[i], data, pointType);
        }
        pathData.ReverseSelf();
        pathData.SetDirty();

        // remove old path values
        directionOverrides = null;
        cutOverrides       = null;
        vertScales         = null;

        // upgrade collider settings
        if (createCollider)
        {
            if (useEdgeCollider)
            {
                colliderMode = Ferr2D_ColliderMode.Edge2D;
            }
            else if (create3DCollider)
            {
                colliderMode = Ferr2D_ColliderMode.Mesh3D;
            }
            else
            {
                colliderMode = Ferr2D_ColliderMode.Polygon2D;
            }
        }
        else
        {
            colliderMode = Ferr2D_ColliderMode.None;
        }

        // upgrade the fill settings
        switch (fill)
        {
        case Ferr2DT_FillMode.None:
            edgeMode = Ferr2D_SectionMode.Normal;
            fillMode = Ferr2D_SectionMode.None; break;

        case Ferr2DT_FillMode.Closed:
            edgeMode = Ferr2D_SectionMode.Normal;
            fillMode = Ferr2D_SectionMode.Normal; break;

        case Ferr2DT_FillMode.InvertedClosed:
            edgeMode = Ferr2D_SectionMode.Invert;
            fillMode = Ferr2D_SectionMode.Invert; break;

        case Ferr2DT_FillMode.FillOnlyClosed:
            edgeMode = Ferr2D_SectionMode.None;
            fillMode = Ferr2D_SectionMode.Normal; break;

        case Ferr2DT_FillMode.Skirt:
            edgeMode = Ferr2D_SectionMode.Normal;
            fillMode = Ferr2D_SectionMode.Normal;
            useSkirt = true; break;

        case Ferr2DT_FillMode.FillOnlySkirt:
            edgeMode = Ferr2D_SectionMode.None;
            fillMode = Ferr2D_SectionMode.Normal;
            useSkirt = true; break;
        }

        isLegacy = false;

                #if UNITY_EDITOR
        UnityEditor.Undo.DestroyObjectImmediate(oldPath);
                #else
        Destroy(oldPath);
                #endif

        Build(true);

                #if UNITY_EDITOR
        UnityEditor.SceneView.RepaintAll();
                #endif
    }