Beispiel #1
0
    private void DrawSceneControlPointsHandle(BezierPoint bezierPoint, Vector2 mousePosition, float handleSize)
    {
        if (bezierPoint.pointType != BezierPointType.None)
        {
            Vector3 handle1 = Handles.FreeMoveHandle(bezierPoint.GetHandle1Position(), Quaternion.identity, handleSize, Vector3.zero, Handles.SphereCap);
            Vector3 handle2 = Handles.FreeMoveHandle(bezierPoint.GetHandle2Position(), Quaternion.identity, handleSize, Vector3.zero, Handles.SphereCap);

            Handles.DrawLine(bezierPoint.GetPosition(), handle1);
            Handles.DrawLine(bezierPoint.GetPosition(), handle2);

            int handleToAdjust = 0;

            if (bezierPoint.GetHandle1Position() != handle1)
            {
                if (Event.current.control)
                {
                    handle1.x = Mathf.Round(mousePosition.x / bezierCurve.snapSize) * bezierCurve.snapSize;
                    handle1.y = Mathf.Round(mousePosition.y / bezierCurve.snapSize) * bezierCurve.snapSize;
                }

                Undo.RecordObject(target, "Move Handle Point 1");
                bezierPoint.SetHandle1Position(handle1);

                if (bezierPoint.pointType == BezierPointType.Connected)
                {
                    handleToAdjust = 2;
                }
            }
            if (bezierPoint.GetHandle2Position() != handle2)
            {
                if (Event.current.control)
                {
                    handle2.x = Mathf.Round(mousePosition.x / bezierCurve.snapSize) * bezierCurve.snapSize;
                    handle2.y = Mathf.Round(mousePosition.y / bezierCurve.snapSize) * bezierCurve.snapSize;
                }

                Undo.RecordObject(target, "Move Handle Point 2");
                bezierPoint.SetHandle2Position(handle2);

                if (bezierPoint.pointType == BezierPointType.Connected)
                {
                    handleToAdjust = 1;
                }
            }

            if (bezierPoint.pointType == BezierPointType.Connected)
            {
                if (handleToAdjust == 1)
                {
                    bezierPoint.SetHandle1Position(bezierPoint.GetPosition() + (handle2 - bezierPoint.GetPosition()) * -1.0f);
                }
                if (handleToAdjust == 2)
                {
                    bezierPoint.SetHandle2Position(bezierPoint.GetPosition() + (handle1 - bezierPoint.GetPosition()) * -1.0f);
                }
            }

            if (bezierPoint.pointType == BezierPointType.Connected)
            {
                Color c = new Color(0, 0, 0, 0);
                if (nearBezierPoint == bezierPoint)
                {
                    c = Color.yellow;
                }

                Handles.color = c;
                Quaternion rotation = Handles.Disc(bezierPoint.GetHandlesRotation(), bezierPoint.GetPosition(), Vector3.forward, handleSize * 4.0f, true, 15);
                Handles.color = Color.white;

                if (bezierPoint.GetHandlesRotation() != rotation)
                {
                    Undo.RecordObject(target, "Rotate handle");
                    bezierPoint.SetHandlesRotation(rotation);
                }
            }
        }
    }