Esempio n. 1
0
        private void TryDrawHandleToAnchorLine(Spline instance, int handle_index)
        {
            var position = instance.Points[handle_index].position;

            var anchorIndex = SplinePoint.GetAnchorIndex(instance.GetSplineMode(), handle_index);

            if (anchorIndex < instance.Points.Length)
            {
                var anchorPoint = instance.Points[anchorIndex];
                Handles.color = new Color(0.75f, 0.75f, 0.75f, 1f);
                Handles.DrawLine(position, anchorPoint.position);
            }
        }
Esempio n. 2
0
        private void DrawSelectedSplineHandle(Spline instance, int point_index)
        {
            var splinePoint = instance.Points[point_index];


            Handles.color = Color.white;

            var anyMoved         = false;
            var anyRotated       = false;
            var anyScaled        = false;
            var splinePointDelta = Vector3.zero;

            if (instance.GetSplineSpace() == Space.Self)
            {
                splinePoint = instance.TransformSplinePoint(splinePoint);
            }

            switch (Tools.current)
            {
            case Tool.Move:
                anyMoved = DrawHandle(Vector3.zero, ref splinePoint.position, out splinePointDelta);
                break;

            case Tool.Rotate:
                anyRotated = DrawHandleRotation(splinePoint.position, ref splinePoint.rotation);
                break;

            case Tool.Scale:
                anyScaled = DrawHandleScale(splinePoint.position, ref splinePoint.scale);
                break;
            }

            if (instance.GetSplineSpace() == Space.Self)
            {
                splinePoint = instance.InverseTransformSplinePoint(splinePoint);
            }

            if (anyMoved || anyRotated || anyScaled)
            {
                Undo.RegisterCompleteObjectUndo(instance, "Move Point");

                var original_point = instance.Points[point_index];
                instance.Points[point_index] = splinePoint;
                instance.EnsureSplineStaysClosed();

                if (LockHandleLength)
                {
                    var pointIsHandle = SplinePoint.IsHandle(instance.GetSplineMode(), point_index);
                    if (pointIsHandle)
                    {
                        var anchor_index = SplinePoint.GetAnchorIndex(instance.GetSplineMode(), point_index);
                        var anchor_point = instance.Points[anchor_index];

                        var to_anchor  = splinePoint.position - anchor_point.position;
                        var dir_anchor = to_anchor.normalized;

                        splinePoint.position         = anchor_point.position + dir_anchor * LockedHandleLength;
                        instance.Points[point_index] = splinePoint;
                    }
                }

                UpdateHandlesWhenPointMoved(instance, point_index, splinePointDelta);

                if (anyMoved)
                {
                    var delta_move = splinePoint.position - original_point.position;

                    for (var i = 0; i < SelectedPoints.Count; ++i)
                    {
                        var other_index = SelectedPoints[i];
                        if (other_index == point_index)
                        {
                            continue;
                        }

                        UpdateHandlesWhenPointMoved(instance, other_index, splinePointDelta);

                        instance.Points[other_index].position += delta_move;
                    }

                    Repaint();
                }

                if (anyRotated)
                {
                    var delta_rotation = Quaternion.Inverse(original_point.rotation) * splinePoint.rotation;

                    for (var i = 0; i < SelectedPoints.Count; ++i)
                    {
                        var other_index = SelectedPoints[i];
                        if (other_index == point_index)
                        {
                            continue;
                        }
                        instance.Points[other_index].rotation *= delta_rotation;
                    }

                    Repaint();
                }

                if (anyScaled)
                {
                    var delta_scale = splinePoint.scale - original_point.scale;

                    for (var i = 0; i < SelectedPoints.Count; ++i)
                    {
                        var other_index = SelectedPoints[i];
                        if (other_index == point_index)
                        {
                            continue;
                        }
                        instance.Points[other_index].scale += delta_scale;
                    }

                    Repaint();
                }

                instance.UpdateNative();
            }
        }