protected override void KeyHandles(SplineSampleModifier.Key key, bool edit)
        {
            if (!isOpen)
            {
                return;
            }
            bool         is2D   = user.spline != null && user.spline.is2D;
            SplineSample result = new SplineSample();
            List <SplineSampleModifier.Key> keys = module.GetKeys();

            OffsetModifier.OffsetKey offsetKey = (OffsetModifier.OffsetKey)key;
            user.spline.Evaluate(offsetKey.position, result);
            matrix.SetTRS(result.position, Quaternion.LookRotation(result.direction, result.normal), Vector3.one * result.size);
            Vector3 pos = matrix.MultiplyPoint(offsetKey.offset);

            if (is2D)
            {
                Handles.DrawLine(result.position, result.position + result.right * offsetKey.offset.x * result.size);
                Handles.DrawLine(result.position, result.position - result.right * offsetKey.offset.x * result.size);
            }
            else
            {
                Handles.DrawWireDisc(result.position, result.direction, offsetKey.offset.magnitude * result.size);
            }
            Handles.DrawLine(result.position, pos);

            if (edit)
            {
                Vector3 lastPos = pos;
                pos = SplineEditorHandles.FreeMoveRectangle(pos, HandleUtility.GetHandleSize(pos) * 0.1f);
                if (pos != lastPos)
                {
                    pos   = matrix.inverse.MultiplyPoint(pos);
                    pos.z = 0f;
                    if (is2D)
                    {
                        offsetKey.offset = Vector2.right * pos.x;
                    }
                    else
                    {
                        offsetKey.offset = pos;
                    }
                    user.Rebuild();
                }
            }

            base.KeyHandles(key, edit);
        }
Esempio n. 2
0
        public override void DrawScene()
        {
            Transform camTransform = SceneView.currentDrawingSceneView.camera.transform;

            if (!drag)
            {
                if (finalize)
                {
                    if (rect.width > 0f && rect.height > 0f)
                    {
                        if (!eventModule.control)
                        {
                            ClearSelection();
                        }
                        for (int i = 0; i < points.Length; i++)
                        {
                            Vector2 guiPoint = HandleUtility.WorldToGUIPoint(points[i].position);
                            if (rect.Contains(guiPoint))
                            {
                                Vector3 local = camTransform.InverseTransformPoint(points[i].position);
                                if (local.z >= 0f)
                                {
                                    AddPointSelection(i);
                                }
                            }
                        }
                    }
                    finalize = false;
                }
            }
            else
            {
                rectEnd = Event.current.mousePosition;
                rect    = new Rect(Mathf.Min(rectStart.x, rectEnd.x), Mathf.Min(rectStart.y, rectEnd.y), Mathf.Abs(rectEnd.x - rectStart.x), Mathf.Abs(rectEnd.y - rectStart.y));
                if (rect.width >= minimumRectSize && rect.height >= minimumRectSize)
                {
                    Color col = SplinePrefs.highlightColor;
                    col.a = 0.4f;
                    Handles.BeginGUI();
                    EditorGUI.DrawRect(rect, col);
                    Handles.EndGUI();
                    SceneView.RepaintAll();
                }
            }
            TextAnchor originalAlignment = GUI.skin.label.alignment;
            Color      originalColor     = GUI.skin.label.normal.textColor;

            GUI.skin.label.alignment        = TextAnchor.MiddleCenter;
            GUI.skin.label.normal.textColor = color;

            for (int i = 0; i < points.Length; i++)
            {
                if (isClosed && i == points.Length - 1)
                {
                    break;
                }
                bool    moved      = false;
                bool    isSelected = selectedPoints.Contains(i);
                Vector3 lastPos    = points[i].position;
                Handles.color = Color.clear;
                if (SplinePrefs.showPointNumbers && camTransform.InverseTransformPoint(points[i].position).z > 0f)
                {
                    Handles.Label(points[i].position + Camera.current.transform.up * HandleUtility.GetHandleSize(points[i].position) * 0.3f, (i + 1).ToString());
                }
                if (excludeSelected && isSelected)
                {
                    SplineEditorHandles.FreeMoveRectangle(points[i].position, HandleUtility.GetHandleSize(points[i].position) * 0.1f);
                }
                else
                {
                    points[i].SetPosition(SplineEditorHandles.FreeMoveRectangle(points[i].position, HandleUtility.GetHandleSize(points[i].position) * 0.1f));
                }

                if (lastPos != points[i].position)
                {
                    RecordUndo("Move Points");
                    moved = true;
                    if (isSelected)
                    {
                        for (int n = 0; n < selectedPoints.Count; n++)
                        {
                            if (selectedPoints[n] == i)
                            {
                                continue;
                            }
                            points[selectedPoints[n]].SetPosition(points[selectedPoints[n]].position + (points[i].position - lastPos));
                        }
                    }
                    else
                    {
                        SelectPoint(i);
                    }
                    lastPos = points[i].position;
                }


                if (!moved && editor.eventModule.mouseLeftUp)
                {
                    if (SplineEditorHandles.HoverArea(points[i].position, 0.12f))
                    {
                        if (eventModule.shift)
                        {
                            ShiftSelect(i, points.Length);
                        }
                        else if (eventModule.control)
                        {
                            AddPointSelection(i);
                        }
                        else
                        {
                            SelectPoint(i);
                        }
                    }
                }
                if (!excludeSelected || !isSelected)
                {
                    Handles.color = color;
                    if (isSelected)
                    {
                        Handles.color = SplinePrefs.highlightColor;
                        Handles.DrawWireDisc(points[i].position, -SceneView.currentDrawingSceneView.camera.transform.forward, HandleUtility.GetHandleSize(points[i].position) * 0.14f);
                    }
                    else
                    {
                        Handles.color = color;
                    }
                    Handles.DrawSolidDisc(points[i].position, -SceneView.currentDrawingSceneView.camera.transform.forward, HandleUtility.GetHandleSize(points[i].position) * 0.09f);
                    Handles.color = Color.white;
                }
                moved = false;
            }
            GUI.skin.label.alignment        = originalAlignment;
            GUI.skin.label.normal.textColor = originalColor;

            if (splineType == Spline.Type.Bezier)
            {
                Handles.color = color;
                for (int i = 0; i < selectedPoints.Count; i++)
                {
                    Handles.DrawDottedLine(points[selectedPoints[i]].position, points[selectedPoints[i]].tangent, 4f);
                    Handles.DrawDottedLine(points[selectedPoints[i]].position, points[selectedPoints[i]].tangent2, 4f);
                    Vector3 lastPos = points[selectedPoints[i]].tangent;
                    Vector3 newPos  = SplineEditorHandles.FreeMoveCircle(points[selectedPoints[i]].tangent, HandleUtility.GetHandleSize(points[selectedPoints[i]].tangent) * 0.1f);
                    if (lastPos != newPos)
                    {
                        RecordUndo("Move Tangent");
                        points[selectedPoints[i]].SetTangentPosition(newPos);
                    }
                    lastPos = points[selectedPoints[i]].tangent2;
                    newPos  = SplineEditorHandles.FreeMoveCircle(points[selectedPoints[i]].tangent2, HandleUtility.GetHandleSize(points[selectedPoints[i]].tangent2) * 0.1f);
                    if (lastPos != newPos)
                    {
                        RecordUndo("Move Tangent");
                        points[selectedPoints[i]].SetTangent2Position(newPos);
                    }
                }
            }
            if (isDragging)
            {
                if (eventModule.alt || !SceneView.currentDrawingSceneView.camera.pixelRect.Contains(Event.current.mousePosition) || !eventModule.mouseLeft)
                {
                    FinishDrag();
                }
            }
        }