BezierSpline.AddCurve C# (CSharp) Method

AddCurve() public method

public AddCurve ( ) : void
return void
    public void AddCurve()
    {
        Vector3 point = points[points.Length - 1];
        Array.Resize (ref points, points.Length + 3);
        point.x += 1f;
        points [points.Length - 3] = point;
        point.x += 1f;
        points [points.Length - 2] = point;
        point.x += 1f;
        points [points.Length - 1] = point;

        Array.Resize (ref modes, modes.Length + 1);
        modes[modes.Length - 1] = modes[modes.Length - 2];

        if (loop) {
            points[points.Length - 1] = points[0];
            modes[modes.Length - 1] = modes[0];
        }
    }

Usage Example

    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Loop");
            EditorUtility.SetDirty(spline);
            spline.Loop = loop;
        }

        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }

        if (GUILayout.Button("Add Curve Point"))
        {
            Undo.RecordObject(spline, "Add Curve Point");
            if (selectedIndex == spline.ControlPointCount - 1)
            {
                spline.AddCurve();
            }
            else if (selectedIndex % 3 == 0)
            {
                spline.AddCurve(selectedIndex);
            }
            EditorUtility.SetDirty(spline);
        }
    }
All Usage Examples Of BezierSpline::AddCurve