private static void DrawSelectedPointHandles(int selectedId, Vector3 handlePos, float handleSize)
        {
            PathPoint point = _currentPath.pathData[selectedId];

            Handles.color = Color.yellow;

            if (Tools.current != Tool.Rotate)
            {
                //Draw tangents handles
                for (int i = 0; i < 2; i++)
                {
                    Vector3 tangentPos = CurveSpaceToWorldSpace(point.GetObjectSpaceTangent((PathTangentType)i));
                    Handles.DrawAAPolyLine(6, tangentPos, handlePos);

                    if (Handles.Button(tangentPos, Quaternion.identity, POINT_HANDLE_SIZE * handleSize, POINT_HANDLE_SIZE * 1.1f * handleSize, Handles.SphereHandleCap))
                    {
                        _selectedTangent = (PathTangentType)i;
                    }
                }
            }

            if (_selectedTangent < 0)             //If no tangent is selected
            {
                switch (Tools.current)
                {
                case Tool.Rotate:
                    //Rotate the point roll and tangents
                    SetPointRotation(_currentPath.pathData[selectedId]);
                    break;

                case Tool.Scale:
                    //Scale the point
                    SetPointScale(handlePos, _currentPath.pathData[selectedId]);
                    break;

                default:
                    //Moves curve the point
                    point.position = MovePoint(handlePos);
                    break;
                }
            }
            else
            {
                //Moves the curve tangent point
                PathTangentType oppositeTangent = (PathTangentType)(1 - ((int)_selectedTangent));

                //Edits the position of the selected tangent
                Vector3 tangentPos = CurveSpaceToWorldSpace(point.GetObjectSpaceTangent((PathTangentType)_selectedTangent));
                Vector3 newPos     = MovePoint(tangentPos);

                bool mirrorScale = !Event.current.alt;

                _currentPath.pathData[selectedId].SetObjectSpaceTangent(_selectedTangent, newPos, true, mirrorScale);
            }
        }
Exemple #2
0
        private void DrawBezierCurve()
        {
            int       curves    = _currentPath.pathData.Length - (_currentPath.loopCurve ? 0 : 1);
            Matrix4x4 transform = Matrix4x4.TRS(_currentPath.transform.position, _currentPath.transform.rotation, _currentPath.transform.lossyScale);

            for (int i = 0; i < curves; i++)
            {
                PathPoint p0 = _currentPath.pathData[i];
                PathPoint p1;

                if (i < _currentPath.pathData.Length - 1)
                {
                    p1 = _currentPath.pathData[i + 1];
                }
                else
                {
                    p1 = _currentPath.pathData[0];
                }

                Color bezierColor = !p0.isEmpty ? Color.green : new Color(0.5f, 0.5f, 0.5f, 0.2f);

                Handles.DrawBezier(
                    transform.MultiplyPoint3x4(p0.position),
                    transform.MultiplyPoint3x4(p1.position),
                    transform.MultiplyPoint3x4(p0.GetObjectSpaceTangent(PathTangentType.Out)),
                    transform.MultiplyPoint3x4(p1.GetObjectSpaceTangent(PathTangentType.In)), bezierColor, null, 5.0f);
            }
        }