BezierSpline.Reset C# (CSharp) Method

Reset() public method

public Reset ( ) : void
return void
    public void Reset()
    {
        points = new Vector3[]
        {
            new Vector3(1f, 0f, 0f),
            new Vector3(2f, 0f, 0f),
            new Vector3(3f, 0f, 0f),
            new Vector3(4f, 0f, 0f)
        };

        modes = new BezierControlPointMode[]
        {
            BezierControlPointMode.Free,
            BezierControlPointMode.Free
        };
    }

Usage Example

Exemplo n.º 1
0
    /// <summary>
    /// Given each sub-spline from one node to the next in our path, stitch them all together to form one large bezier spline.
    /// </summary>
    public void CalculatePathSpline()
    {
        // Quick way to remove all previous curves and points.
        // One curve is created during Reset(), so we have to clear that out too
        selectedPathSpline.Reset();
        selectedPathSpline.RemoveCurve();

        for (int currentNodeIndex = 0; currentNodeIndex < selectedPath.Count - 1; currentNodeIndex++)
        {
            selectedPathSpline.AddCurve();

            // -- Set the control point mode.
            // Due to the way that I set up the node positions, free mode is the only one that looks good. I could use Aligned or Mirrored if I added more inbetween nodes, but my setup for creating nodes was kinda garbage
            //  Free mode only is fine for now
            selectedPathSpline.SetControlPointMode(3 * currentNodeIndex, controlPointMode);
            selectedPathSpline.SetControlPointMode(3 * currentNodeIndex + 3, controlPointMode);

            // Find the index of the sub-spline we want, in the node.
            // We have to do this search, since we store multiple sub-splines in each node
            int          index     = selectedPath[currentNodeIndex].connectedNodes.IndexOf(selectedPath[currentNodeIndex + 1]);
            BezierSpline subSpline = selectedPath[currentNodeIndex].connectedNodePaths[index];

            Vector3 toNode = selectedPath[currentNodeIndex].transform.position - transform.position;

            // -- Copy over each control point of the spline
            // Need to do this in this weird order, because we have to set the control points after the pivot points.
            // BezierSpline.SetControlPoints should probably get refactored to include an overload method to avoid this, but oh well
            selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 0, toNode + subSpline.GetControlPoint(0));
            selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 1, toNode + subSpline.GetControlPoint(1));
            selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 3, toNode + subSpline.GetControlPoint(3));
            selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 2, toNode + subSpline.GetControlPoint(2));
        }
    }
All Usage Examples Of BezierSpline::Reset