void FreeNormal(int index)
        {
            Handles.color = highlightColor;
            Handles.DrawWireDisc(points[index].position, points[index].normal, HandleUtility.GetHandleSize(points[index].position) * 0.25f);
            Handles.DrawWireDisc(points[index].position, points[index].normal, HandleUtility.GetHandleSize(points[index].position) * 0.5f);
            Handles.color = color;
            Handles.DrawLine(points[index].position, points[index].position + HandleUtility.GetHandleSize(points[index].position) * points[index].normal);
            Vector3 normalPos  = points[index].position + points[index].normal * HandleUtility.GetHandleSize(points[index].position);
            Vector3 lastNormal = points[index].normal;

            normalPos  = SplineEditorHandles.FreeMoveCircle(normalPos, HandleUtility.GetHandleSize(normalPos) * 0.1f);
            normalPos -= points[index].position;
            normalPos.Normalize();
            if (normalPos == Vector3.zero)
            {
                normalPos = Vector3.up;
            }
            if (lastNormal != normalPos)
            {
                RecordUndo("Edit Point Normals");
                points[index].normal = normalPos;
                Quaternion delta = Quaternion.FromToRotation(lastNormal, normalPos);
                for (int n = 0; n < selectedPoints.Count; n++)
                {
                    if (selectedPoints[n] == index)
                    {
                        continue;
                    }
                    points[selectedPoints[n]].normal = delta * points[selectedPoints[n]].normal;
                }
            }
        }
示例#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();
                }
            }
        }