AddCurve() public méthode

public AddCurve ( ) : void
Résultat void
    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);
        }
    }
Exemple #2
0
    public void UpdateTireBezier()
    {
        if (TireSpline == null)
        {
            //first time, create spline
            TireSpline = gameObject.AddComponent <BezierSpline>();
            TireSpline.Reset();
            TireSpline.AddCurve();
            TireSpline.AddCurve();
            TireSpline.AddCurve();
            TireSpline.AddCurve();
        }
        float SmoothValue = 0.025f;

        Vector3 p1 = new Vector3(RimRadius, RimWidth / 2, 0);

        TireSpline.SetControlPoint(0, p1);
        TireSpline.SetControlPoint(1, p1 + new Vector3(Mathf.Min(SmoothValue, TireHeight * _SideWallSize), 0, 0));
        //Mathf.Max (-value,(WheelDiameter+TireHeight*_SideWallSize) - _WheelDiameter)
        Vector3 p2 = new Vector3(RimRadius + TireHeight * _SideWallSize, TireWidth / 2, 0);

        TireSpline.SetControlPoint(3, p2);
        TireSpline.SetControlPoint(2, p2 + new Vector3(Mathf.Max(-SmoothValue, -TireHeight * _SideWallSize), 0, 0));
        TireSpline.SetControlPoint(4, p2 + new Vector3(TireHeight * (1 - _SideWallSize) * _Curvature, 0, 0));

        Vector3 p3 = new Vector3(RimRadius + TireHeight, (TireWidth / 2) * _FlatPart, 0);

        TireSpline.SetControlPoint(6, p3);
        TireSpline.SetControlPoint(5, p3 + new Vector3(0, (TireWidth / 2) * (1 - _FlatPart) * _Curvature, 0));
        TireSpline.SetControlPoint(7, p3 + new Vector3(0, Mathf.Max(-SmoothValue, Mathf.Clamp01(-p3.y)), 0));

        Vector3 p4 = new Vector3(RimRadius + TireHeight, (-TireWidth / 2) * _FlatPart, 0);

        TireSpline.SetControlPoint(9, p4);
        TireSpline.SetControlPoint(8, p4 + new Vector3(0, Mathf.Min(SmoothValue, Mathf.Clamp01(-p4.y)), 0));
        TireSpline.SetControlPoint(10, p4 + new Vector3(0, (-TireWidth / 2) * (1 - _FlatPart) * _Curvature, 0));

        Vector3 p5 = new Vector3(RimRadius + TireHeight * _SideWallSize, -TireWidth / 2, 0);

        TireSpline.SetControlPoint(12, p5);
        TireSpline.SetControlPoint(11, p5 + new Vector3(TireHeight * (1 - _SideWallSize) * _Curvature, 0, 0));
        TireSpline.SetControlPoint(13, p5 + new Vector3(Mathf.Max(-SmoothValue, -TireHeight * _SideWallSize), 0, 0));

        Vector3 p6 = new Vector3(RimRadius, -RimWidth / 2, 0);

        TireSpline.SetControlPoint(15, p6);
        TireSpline.SetControlPoint(14, p6 + new Vector3(Mathf.Min(SmoothValue, TireHeight * _SideWallSize), 0, 0));
    }
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;

        int index = spline.GetSelectedIndex();

        if (index >= 0 && index < spline.ControlPointCount)
        {
            DrawSelectedPointInspector(index); Debug.Log("After Draw Call" + index);
        }

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    // -------------
    // Inspector GUI
    // -------------

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        spline = target as BezierSpline;

        // If we've selected a spline control point, show its transform in the inspector
        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }

        // Button for adding new curves!
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }

        // Button for adding new curves!
        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(spline, "Remove Curve");
            spline.RemoveCurve();
            EditorUtility.SetDirty(spline);
        }
    }
Exemple #5
0
 private void AddNewCurve()
 {
     Undo.RecordObject(spline, "Add Curve");
     spline.AddCurve();
     EditorUtility.SetDirty(spline);
     Undo.FlushUndoRecordObjects();
 }
    /* Add a new button to the inspector to add a new curve */
    public override void OnInspectorGUI()
    {
        /* If we want all the members to be shown in the inspector */
        // DrawDefaultInspector();

        spline = target as BezierSpline;

        /* Add a Loop option to the inspector */
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        /* Show on the inspector stats of the selected point */
        if (selectedIndex >= 0 && selectedIndex < spline.GetControlPointsCount)
        {
            // call this every time the inspector is redrawn
            DrawSelectedPointInspector();
        }
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add New Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
 public override void OnInspectorGUI()
 {
     b_spline = target as BezierSpline;
     //showDirections = GUILayout.Toggle(showDirections, "Show Direction");
     EditorGUI.BeginChangeCheck();
     showDirections = EditorGUILayout.Toggle("Show Directions", b_spline.showDirections);
     if (EditorGUI.EndChangeCheck())
     {
         Undo.RecordObject(b_spline, "Toogle Show Directions");
         EditorUtility.SetDirty(b_spline);
         b_spline.showDirections = showDirections;
     }
     EditorGUI.BeginChangeCheck();
     bool looped = EditorGUILayout.Toggle("Loop", b_spline.IsLooped);
     if (EditorGUI.EndChangeCheck())
     {
         Undo.RecordObject(b_spline, "Toogle Loop");
         EditorUtility.SetDirty(b_spline);
         b_spline.IsLooped = looped;
     }
     if (selectedIndex >= 0 && selectedIndex < b_spline.ControlPointCount)
     {
         DrawSelectedPointInspector();
     }
     if (GUILayout.Button("Add Curve"))
     {
         Undo.RecordObject(b_spline, "Add Curve");
         b_spline.AddCurve();
         EditorUtility.SetDirty(b_spline);
     }
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        spline = target as BezierSpline;

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop Last Point", spline.GetLoop());
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Loop Last Point");
            EditorUtility.SetDirty(spline);
            spline.SetLoop(loop);
        }

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

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }

        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(spline, "Remove Curve");
            spline.RemoveCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        spline = target as BezierSpline;

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop Last Point", spline.GetLoop());

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Loop Last Point");
            EditorUtility.SetDirty(spline);
            spline.SetLoop(loop);
        }

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

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }

        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(spline, "Remove Curve");
            spline.RemoveCurve();
            EditorUtility.SetDirty(spline);
        }
    }
Exemple #10
0
        public override void OnInspectorGUI()
        {
            _spline = target as BezierSpline;

            if (_selectedIndex >= 0 && _selectedIndex < _spline.ControlPointCount)
            {
                DrawSelectedPointInspector();

                if (!_spline.IsHandle(_selectedIndex) &&
                    _spline.CurveCount > 1 &&
                    GUILayout.Button("Delete Curve"))
                {
                    Undo.RecordObject(_spline, "Delete Curve");
                    _spline.DeletePoint(_selectedIndex);
                    EditorUtility.SetDirty(_spline);
                }
            }

            if (GUILayout.Button("Add Curve"))
            {
                Undo.RecordObject(_spline, "Add Curve");
                _spline.AddCurve();
                EditorUtility.SetDirty(_spline);
            }
        }
Exemple #11
0
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        // checks to see if selected index is in the array. it might not be if it were deleted
        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }


        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
        }
    }
Exemple #12
0
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
        if (GUILayout.Button("Flip Spline"))
        {
            Undo.RecordObject(spline, "Add Curve");
            EditorUtility.SetDirty(spline);
            spline.ReverseSpline();
        }
    }
    /* To actually be able to add a curve, we have to add a button to our spline's inspector.
     * We can customize the inspector that Unity uses for our component by overriding the OnInspectorGUI method of BezierSplineInspector.
     * Note that this is not a special Unity method, it relies on inheritance.
     * To keep drawing the default inspector, we call the DrawDefaultInspector method.
     * Then we use GUILayout to draw a button, which when clicked adds a curve.
     */
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        /* While we're at it, we also no longer want to allow direct access to the array in the inspector,
         * so remove the call to DrawDefaultInspector. To still allow changes via typing, let's show a vector field for the selected point.
         */
        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
Exemple #14
0
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

        //	targetPos = EditorGUILayout.Vector3Field ("TargetPos",targetPos);
        //	EditorGUILayout.FloatField ("Distance", distance);
        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"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    /// <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));
        }
    }
Exemple #16
0
    public void SetPoints()
    {
        targetSpline = GetComponent <BezierSpline>();
        targetSpline.Reset();

        int requiredCurveCount = splinePointTargetsTranforms.Length / 4;

        if (splinePointTargetsTranforms.Length % 4 != 0)
        {
            requiredCurveCount++;
        }

        for (int i = 0; i < requiredCurveCount; i++)
        {
            targetSpline.AddCurve();
        }

        splinePointPositions = new Vector3[splinePointTargetsTranforms.Length];

        for (int i = 0; i < splinePointTargetsTranforms.Length; i++)
        {
            splinePointPositions[i] = splinePointTargetsTranforms[i].transform.localPosition;
        }

        targetSpline.SetMultipleControlPoints(splinePointPositions, pointMode);
    }
Exemple #17
0
    public override void OnInspectorGUI()
    {
        GUI.enabled = false;
        EditorGUILayout.ObjectField("Script:", MonoScript.FromMonoBehaviour((BezierSpline)target), typeof(BezierSpline), false);
        GUI.enabled = true;

        spline = target as BezierSpline;
        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"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        if (renderer == null)
        {
            renderer = spline.GetComponentInChildren <RacetrackRenderer>();
        }

        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"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
Exemple #19
0
    /// <summary>
    /// OnInspectorGUI()方法重写,自定义inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;

        EditorGUI.BeginChangeCheck();
        //EditorGUILayout.Toggle():开关按钮
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        //绘制默认的检查器,将参数显示在inspertor上
        //DrawDefaultInspector();

        if (selectIndex >= 0 && selectIndex < spline.ControlPointCout)
        {
            DrawSelectedPointInspector();
        }
        //使用GUILayout绘制按钮
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toogle Loop");
            EditorUtility.SetDirty(spline);
            spline.Loop = loop;
        }

        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
        if (GUILayout.Button("Flip Spline"))
        {
            Undo.RecordObject(spline, "Add Curve");
            EditorUtility.SetDirty(spline);
            spline.ReverseSpline();
        }
    }
Exemple #21
0
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;
        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();
        }

        //var numPts = spline.ControlPointCount;
        //for (int i = 0; i < numPts; i++)
        //{
        //    var pt = spline.GetControlPoint(i);
        //    EditorGUILayout.LabelField(pt.ToString());
        //}

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    public override void OnInspectorGUI()
    {
        spline = target as BezierSpline;

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        selectedIndex = EditorGUILayout.IntField("Index:",
                                                 (int)Mathf.Clamp((float)selectedIndex, -1.0f, (float)spline.ControlPointCount - 1.0f));
        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
    }
    private void CurveEditor()
    {
        if (spline == null)
        {
            spline = master.spline;
        }

        EditorGUI.BeginChangeCheck();

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(spline, "Add Curve");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(spline, "Remove Curve");
            spline.RemoveCurve(selectedIndex);
            selectedIndex = -1;
            EditorUtility.SetDirty(spline);
        }
        if (GUILayout.Button("Reset"))
        {
            Undo.RecordObject(spline, "Reset");
            spline.Reset();
            master.Reset();
            selectedIndex = -1;
            EditorUtility.SetDirty(spline);
        }

        GUILayout.BeginVertical("box");
        GUILayout.Space(5);
        bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);

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

        GUILayout.Label("    Curve Lenght: " + spline.GetCurveLenght());
        GUILayout.Space(5);
        GUILayout.EndVertical();

        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        else
        {
            GUILayout.BeginVertical("box");
            GUILayout.Space(5);
            GUILayout.Label("   Select point to edit!");
            GUILayout.Space(5);
            GUILayout.EndVertical();
        }
    }
Exemple #24
0
    public override void OnInspectorGUI()
    {
        BezierSpline spline = (BezierSpline)target;

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Add curve"))
        {
            if (selectedCurveType == CurveType.Line)
            {
                spline.AddCurve(new Vector3[2] {
                    Vector3.zero, Vector3.forward
                });
            }
            else if (selectedCurveType == CurveType.Quadratic)
            {
                spline.AddCurve(new Vector3[3] {
                    Vector3.zero, Vector3.forward, new Vector3(0f, 0f, 2f)
                });
            }
            else //cubic
            {
                spline.AddCurve
                    (new Vector3[4]
                {
                    Vector3.zero,
                    Vector3.forward,
                    new Vector3(0f, 0f, 2f),
                    new Vector3(0f, 0f, 3f)
                }
                    );
            }
        }

        selectedCurveType = (CurveType)EditorGUILayout.EnumPopup(selectedCurveType);
        if (GUILayout.Button("Delete last curve"))
        {
            spline.DeleteLastCurve();
        }
        GUILayout.EndHorizontal();


        GUILayout.BeginHorizontal();
        showTangents = GUILayout.Button("Show tangents");
        showNormals  = GUILayout.Button("Show normals");
        GUILayout.EndHorizontal();
    }
Exemple #25
0
        private void AddPathButton_Click(object sender, EventArgs e)
        {
            BezierSpline spline = new BezierSpline();

            spline.AddCurve(new CubicBezier(new Vector2(50.0f, 0.0f), new Vector2(50.0f, 10.0f), new Vector2(50.0f, 20.0f), new Vector2(50.0f, 30.0f)));
            mFormation.Splines.Add(spline);
            RefreshPaths();
        }
Exemple #26
0
 public override void OnInspectorGUI()
 {
     DrawDefaultInspector();
     if (GUILayout.Button("Add Curve"))
     {
         Undo.RecordObject(spline, "Add Curve");
         spline.AddCurve();
         EditorUtility.SetDirty(spline);
     }
 }
Exemple #27
0
        /// <summary>
        /// gets a BezierSpline for the SvgPath
        /// </summary>
        /// <returns>The bezier spline for path.</returns>
        public BezierSpline GetBezierSplineForPath()
        {
            Insist.IsTrue(IsPathCubicBezier(), "SvgPath is not a cubic bezier");

            var bezier = new BezierSpline();

            for (var i = 1; i < Segments.Count; i++)
            {
                var cub = Segments[i] as SvgCubicCurveSegment;
                bezier.AddCurve(cub.Start, cub.FirstCtrlPoint, cub.SecondCtrlPoint, cub.End);
            }

            return(bezier);
        }
Exemple #28
0
        private void SectionAddCurve()
        {
            Header("Add Curve");

            EditorGUI.BeginChangeCheck();
            if (GUILayout.Button("Add New Curve"))
            {
                Undo.RecordObject(spline, "Add Curve");
                spline.AddCurve();
                EditorUtility.SetDirty(spline);
            }

            Footer();
        }
 public override void OnInspectorGUI()
 {
     spline = target as BezierSpline;
     if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
     {
         DrawSelectedPointInspector();
     }
     if (GUILayout.Button("Add Curve"))
     {
         Undo.RecordObject(spline, "Add Curve");
         spline.AddCurve();
         EditorUtility.SetDirty(spline);
     }
 }
 //create a custom inspetor gui
 public override void OnInspectorGUI()
 {
     //DrawDefaultInspector();//do the defualt stuff
     spline = target as BezierSpline;        //the spline
     if (selectedIndex >= 0 && selectedIndex < spline.controlPointCount)
     {
         DrawSelectedPointInspector();
     }
     if (GUILayout.Button("Add Curve"))          //if the button add curve is clicked
     {
         Undo.RecordObject(spline, "Add Curve");
         spline.AddCurve();            //add a curve
         EditorUtility.SetDirty(spline);
     }
 }
Exemple #31
0
    public void Generate()
    {
        var previousAnchor  = spline.GetControlPoint(spline.ControlPointCount - 1);
        var previousControl = spline.GetControlPoint(spline.ControlPointCount - 2);

        // Random random anchors with control points automatically smoothed
        var anchors = GenerateAnchors(anchorGenerationCount, previousAnchor, ref forward);

        splinePoints = SmoothBezierFromAnchors(anchors);

        for (var i = 1; i < splinePoints.Length; i += 3)
        {
            spline.AddCurve(splinePoints[i], splinePoints[i + 1], splinePoints[i + 2]);
            spline.SetControlPointMode(spline.ControlPointCount - 1, BezierControlPointMode.Mirrored);
        }
        mesh.UpdateMesh();
    }
Exemple #32
0
        void MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (mCurrentSpline != null)
            {
                int x = (int)((((float)e.X) / ((float)GameHandle.Width)) * 100.0f);
                int y = (int)((((float)e.Y) / ((float)GameHandle.Height)) * 100.0f);

                Vector2     vect = new Vector2(x, y);
                CubicBezier bez  = mCurrentParentSpline.GetCurve(mCurrentParentSpline.CurveCount - 1);
                Vector2     prev = bez.Points[3];

                Vector2 p1 = Vector2.Lerp(prev, vect, 0.3f);
                Vector2 p2 = Vector2.Lerp(prev, vect, 0.6f);

                mCurrentParentSpline.AddCurve(new CubicBezier(prev, p1, p2, vect));
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();

            if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
            {
                DrawSelectedPointInspector();
            }
            if (GUILayout.Button("Add Curve"))
            {
                Undo.RecordObject(spline, "Add Curve");
                spline.AddCurve();
                EditorUtility.SetDirty(spline);
            }
        }
    public void GenerateTrack()
    {
        trackPoints.Clear();

        Vector3 point = Vector3.zero;

        float radiusAmount = 0f;

        centerTrackPoints = new Vector3[curvePoints];

        // Set Curves on Bezier Spline
        bezierSpline = GetComponent<BezierSpline> ();
        bezierSpline.Reset ();
        //		bezierSpline.ClearControlPoints ();
        bezierSpline.Loop = true;
        bezierSpline.OnBezierPointChanged = UpdateTrackMesh;

        for (int i = 0; i < curvePoints; i++)
        {
            radiusAmount = ((float)i / curvePoints) * (2*Mathf.PI);
            point = new Vector3(radius.x * Mathf.Cos (frequency.x * radiusAmount), 0f, radius.y * Mathf.Sin (frequency.y * radiusAmount));

            point = point * radiusSizeFactor;
            centerTrackPoints[i] = point;

            trackPoints.Add (point);

            // Set points in the Bezier curve
            if (i > 0 && i % 3 == 0)
                bezierSpline.AddCurve ();

            bezierSpline.SetControlPoint (i, point);
        }

        UpdateTrackMesh ();
    }