private void OnSceneGUI()
    {
        _spline          = target as BezierSplines;
        _handleTransform = _spline.transform;
        _handleRotation  = Tools.pivotRotation == PivotRotation.Local ? _handleTransform.rotation : Quaternion.identity;

        if (_spline.ControlPointCount != 0)
        {
            Vector3 p0 = ShowPoint(0);
            for (int i = 1; i < _spline.ControlPointCount; i += 3)
            {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.gray;

                if (m_drawTangents)
                {
                    Handles.DrawLine(p0, p1);
                    Handles.DrawLine(p2, p3);
                }

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
                p0 = p3;
            }

            ShowDirections();
        }
    }
Esempio n. 2
0
    private void OnSceneGUI()
    {
        spline          = target as BezierSplines;
        handleTransform = spline.transform;
        handleRotation  = Tools.pivotRotation == PivotRotation.Local ?
                          handleTransform.rotation : Quaternion.identity;

        Vector3 p0 = ShowPoint(0);

        for (int i = 1; i < spline.ControlPointCount; i += 3)
        {
            Vector3 p1 = ShowPoint(i);
            Vector3 p2 = ShowPoint(i + 1);
            Vector3 p3 = ShowPoint(i + 2);

            Handles.color = Color.gray;
            Handles.DrawLine(p0, p1);
            Handles.DrawLine(p2, p3);

            Handles.DrawBezier(p0, p3, p1, p2, spline.curveColor, null, 2f);
            p0 = p3;
        }
        if (spline.visibleWhenNotSelected)
        {
            SceneView.onSceneGUIDelegate -= OnScene;
            SceneView.onSceneGUIDelegate += OnScene;
        }
        if (!spline.visibleWhenNotSelected)
        {
            SceneView.onSceneGUIDelegate -= OnScene;
        }
    }
Esempio n. 3
0
    private Vector3 GetClosestPoint(BezierSplines path)
    {
        Vector3 currentPoint = Vector3.zero;

        for (float i = 0f; i < 1f; i += precision)
        {
            Vector3 point = path.GetPoint(i);

            //Debug.Log("point is now" + point + " " + i + "sensitivy " + precision);
            //Debug.Log("Distance to currentPoint " + Vector3.Distance(this.transform.position, point));
            //Debug.Log("Distance to previous Point " + Vector3.Distance(this.transform.position, currentPoint));
            if (Vector3.Distance(this.transform.position, point) <
                (Vector3.Distance(this.transform.position, currentPoint)))
            {
                //Debug.Log("point is closer than currentWayPoint");
                currentPoint = point;
            }
            else
            {
                //Debug.Log("i" + i);
                progressPercentage = i;
                break;
            }
        }


        return(currentPoint);
    }
    public override void OnInspectorGUI()
    {
        _spline = target as BezierSplines;
        DrawDefaultInspector();

        EditorGUILayout.Space();
        EditorGUILayout.LabelField(" ", "Custom editor part");

        EditorGUI.BeginChangeCheck();
        var drawTangents = EditorGUILayout.ToggleLeft("Draw Tangents", m_drawTangents);

        if (EditorGUI.EndChangeCheck())
        {
            m_drawTangents = drawTangents;
        }

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

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add curve"))
        {
            Undo.RecordObject(_spline, "Add curve");
            _spline.AddCurve();
            EditorUtility.SetDirty(_spline);
        }
        if (GUILayout.Button("Incert Curve in index"))
        {
            Undo.RecordObject(_spline, "Inert curve");
            _spline.InsertCurve(curveIndexToAdd);
            EditorUtility.SetDirty(_spline);
        }
        curveIndexToAdd = EditorGUILayout.IntSlider(curveIndexToAdd, 0, _spline.CurveCount);
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(_spline, "Remove Curve");
            _spline.RemoveCurve();
            EditorUtility.SetDirty(_spline);
        }
        if (GUILayout.Button("Remove At Curve"))
        {
            Undo.RecordObject(_spline, "Remove at Curve");
            _spline.RemoveAtCurve(curveIndexToRemove);
            EditorUtility.SetDirty(_spline);
        }
        curveIndexToRemove = EditorGUILayout.IntSlider(curveIndexToRemove, 0, _spline.CurveCount - 1);
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        spline = target as BezierSplines;
        //if(spline.Orientations == null)
        //{
        //    spline._fixOldVersion();
        //}
        EditorGUI.BeginChangeCheck();
        bool visible = EditorGUILayout.Toggle("Always Visible", spline.visibleWhenNotSelected);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Visiblity");
            EditorUtility.SetDirty(spline);
            spline.visibleWhenNotSelected = visible;
        }
        EditorGUI.BeginChangeCheck();
        Color splineColor = EditorGUILayout.ColorField("Spline Color", spline.curveColor);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Spline color change");
            EditorUtility.SetDirty(spline);
            spline.curveColor = splineColor;
        }
        EditorGUI.BeginChangeCheck();
        float duration = EditorGUILayout.FloatField("Path traverse duration", spline.duration);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Spline duration changed");
            EditorUtility.SetDirty(spline);
            spline.duration = duration;
        }
        EditorGUI.BeginChangeCheck();
        float speed = EditorGUILayout.FloatField("Path traverse speed", spline.speed);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Spline speed changed");
            EditorUtility.SetDirty(spline);
            spline.speed = speed;
        }

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

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Loop");
            EditorUtility.SetDirty(spline);
            spline.Loop = loop;
        }
        EditorGUI.BeginChangeCheck();
        float newCurveDistancing = EditorGUILayout.FloatField("nodes distancing by new curve", spline.newCurveDistancing);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Spline new line distancing changed");
            EditorUtility.SetDirty(spline);
            spline.newCurveDistancing = newCurveDistancing;
        }
        EditorGUI.BeginChangeCheck();
        float gizmosradius = EditorGUILayout.FloatField("helper gizmos radius", spline.gizmosradius);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Spline gizmos radius changed");
            EditorUtility.SetDirty(spline);
            spline.gizmosradius = gizmosradius;
        }
        EditorGUI.BeginChangeCheck();
        bool showGizmosPermanent = EditorGUILayout.Toggle("Permanently Show gizmos", spline.ShowGizmosPermanent);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle permanent gizmos visibility");
            EditorUtility.SetDirty(spline);
            spline.ShowGizmosPermanent = showGizmosPermanent;
        }
        EditorGUI.BeginChangeCheck();
        bool showGizmos = EditorGUILayout.Toggle("Show gizmos on selection", spline.ShowGizmos);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle gizmos visibility");
            EditorUtility.SetDirty(spline);
            spline.ShowGizmos = showGizmos;
        }
        if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        //_choiceIndex = EditorGUILayout.Popup(_choiceIndex, _choices);
        //Undo.RecordObject(spline, "bspline mode change");
        //spline.pathMode = _choices[_choiceIndex];
        //EditorUtility.SetDirty(spline);
        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.DeleteCurve();
            EditorUtility.SetDirty(spline);
        }
    }