コード例 #1
0
        public override bool SceneEdit(ref SplinePoint[] points, ref List <int> selected)
        {
            bool      change       = false;
            Transform camTransform = SceneView.currentDrawingSceneView.camera.transform;

            if (focused)
            {
                if (!drag)
                {
                    if (finalize)
                    {
                        if (rect.width > 0f && rect.height > 0f)
                        {
                            if (!additive)
                            {
                                ClearSelection(ref selected);
                            }
                            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, ref selected);
                                        change = true;
                                    }
                                }
                            }
                        }
                        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;
                        if (deleteMode)
                        {
                            col = Color.red;
                        }
                        col.a     = 0.4f;
                        GUI.color = col;
                        Handles.BeginGUI();
                        GUI.Box(rect, "", SplineEditorGUI.whiteBox);
                        GUI.color = Color.white;
                        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 = computer.editorPathColor;

            for (int i = 0; i < points.Length; i++)
            {
                if (computer.isClosed && i == points.Length - 1)
                {
                    break;
                }
                bool    moved      = false;
                bool    isSelected = selected.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 (!change)
                {
                    if (lastPos != points[i].position)
                    {
                        moved  = true;
                        change = true;
                        if (isSelected)
                        {
                            for (int n = 0; n < selected.Count; n++)
                            {
                                if (selected[n] == i)
                                {
                                    continue;
                                }
                                points[selected[n]].SetPosition(points[selected[n]].position + (points[i].position - lastPos));
                            }
                        }
                        else if (selectOnMove)
                        {
                            selected.Clear();
                            selected.Add(i);
                            SceneView.RepaintAll();
                        }
                    }
                }

                if (!moved)
                {
                    if (SplineEditorHandles.HoverArea(points[i].position, 0.12f) && click)
                    {
                        if (shift)
                        {
                            ShiftSelect(i, points.Length, ref selected);
                        }
                        else if (additive)
                        {
                            AddPointSelection(i, ref selected);
                        }
                        else
                        {
                            SelectPoint(i, ref selected);
                        }
                        SceneView.RepaintAll();
                        change = true;
                    }
                }
                if (!excludeSelected || !isSelected)
                {
                    Handles.color = computer.editorPathColor;
                    if (deleteMode)
                    {
                        Handles.color = Color.red;
                    }
                    else if (isSelected)
                    {
                        Handles.color = SplinePrefs.highlightColor;
                    }
                    SplineEditorHandles.DrawRectangle(points[i].position, Quaternion.LookRotation(-SceneView.currentDrawingSceneView.camera.transform.forward), HandleUtility.GetHandleSize(points[i].position) * 0.1f);
                }
                moved = false;
            }
            GUI.skin.label.alignment        = originalAlignment;
            GUI.skin.label.normal.textColor = originalColor;

            if (computer.type == Spline.Type.Bezier)
            {
                Handles.color = computer.editorPathColor;
                for (int i = 0; i < selected.Count; i++)
                {
                    Handles.DrawDottedLine(points[selected[i]].position, points[selected[i]].tangent, 6f);
                    Handles.DrawDottedLine(points[selected[i]].position, points[selected[i]].tangent2, 6f);
                    Vector3 lastPos = points[selected[i]].tangent;
                    points[selected[i]].SetTangentPosition(SplineEditorHandles.FreeMoveCircle(points[selected[i]].tangent, HandleUtility.GetHandleSize(points[selected[i]].tangent) * 0.1f));
                    if (lastPos != points[selected[i]].tangent)
                    {
                        change = true;
                    }
                    lastPos = points[selected[i]].tangent2;
                    points[selected[i]].SetTangent2Position(SplineEditorHandles.FreeMoveCircle(points[selected[i]].tangent2, HandleUtility.GetHandleSize(points[selected[i]].tangent2) * 0.1f));
                    if (lastPos != points[selected[i]].tangent2)
                    {
                        change = true;
                    }
                }
            }
            return(change);
        }
コード例 #2
0
        public override bool SceneEdit(ref SplinePoint[] points, ref List <int> selected)
        {
            bool change = false;

            if (!drag)
            {
                if (finalize)
                {
                    if (rect.width > 0f && rect.height > 0f)
                    {
                        if (!additive)
                        {
                            ClearSelection(ref selected);
                        }
                        for (int i = 0; i < points.Length; i++)
                        {
                            Vector2 guiPoint = HandleUtility.WorldToGUIPoint(points[i].position);
                            if (rect.Contains(guiPoint))
                            {
                                AddPointSelection(i, ref selected);
                                change = true;
                            }
                        }
                    }
                    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 = SplineEditorGUI.selectionColor;
                    if (deleteMode)
                    {
                        col = Color.red;
                    }
                    col.a     = 0.4f;
                    GUI.color = col;
                    Handles.BeginGUI();
                    GUI.Box(rect, "", SplineEditorGUI.whiteBox);
                    Handles.EndGUI();
                    SceneView.RepaintAll();
                }
            }

            for (int i = 0; i < points.Length; i++)
            {
                if (computer.isClosed && i == points.Length - 1)
                {
                    break;
                }
                bool    moved      = false;
                bool    isSelected = selected.Contains(i);
                Vector3 lastPos    = points[i].position;
                Handles.color = Color.clear;
                if (excludeSelected && isSelected)
                {
                    Handles.FreeMoveHandle(points[i].position, Quaternion.identity, HandleUtility.GetHandleSize(points[i].position) * 0.1f, Vector3.zero, Handles.RectangleCap);
                }
                else
                {
                    points[i].SetPosition(Handles.FreeMoveHandle(points[i].position, Quaternion.identity, HandleUtility.GetHandleSize(points[i].position) * 0.1f, Vector3.zero, Handles.RectangleCap));
                }

                if (!change)
                {
                    if (lastPos != points[i].position)
                    {
                        moved  = true;
                        change = true;
                        if (isSelected)
                        {
                            for (int n = 0; n < selected.Count; n++)
                            {
                                if (selected[n] == i)
                                {
                                    continue;
                                }
                                points[selected[n]].SetPosition(points[selected[n]].position + (points[i].position - lastPos));
                            }
                        }
                        else if (selectOnMove)
                        {
                            selected.Clear();
                            selected.Add(i);
                            SceneView.RepaintAll();
                        }
                    }
                }

                if (!moved && !isSelected)
                {
                    if (SplineEditorHandles.HoverArea(points[i].position, 0.12f) && click)
                    {
                        if (additive)
                        {
                            AddPointSelection(i, ref selected);
                        }
                        else
                        {
                            SelectPoint(i, ref selected);
                        }
                        SceneView.RepaintAll();
                        change = true;
                    }
                }
                if (!excludeSelected || !isSelected)
                {
                    Handles.color = computer.editorPathColor;
                    if (deleteMode)
                    {
                        Handles.color = Color.red;
                    }
                    else if (isSelected)
                    {
                        Handles.color = SplineEditorGUI.selectionColor;
                    }
                    Handles.RectangleCap(i, points[i].position, Quaternion.LookRotation(-SceneView.currentDrawingSceneView.camera.transform.forward), HandleUtility.GetHandleSize(points[i].position) * 0.1f);
                }
                moved = false;
            }

            if (computer.type == Spline.Type.Bezier)
            {
                Handles.color = computer.editorPathColor;
                for (int i = 0; i < selected.Count; i++)
                {
                    Handles.DrawDottedLine(points[selected[i]].position, points[selected[i]].tangent, 6f);
                    Handles.DrawDottedLine(points[selected[i]].position, points[selected[i]].tangent2, 6f);
                    Vector3 lastPos = points[selected[i]].tangent;
                    points[selected[i]].SetTangentPosition(Handles.FreeMoveHandle(points[selected[i]].tangent, Quaternion.identity, HandleUtility.GetHandleSize(points[selected[i]].tangent) * 0.1f, Vector3.zero, Handles.CircleCap));
                    if (lastPos != points[selected[i]].tangent)
                    {
                        change = true;
                    }
                    lastPos = points[selected[i]].tangent2;
                    points[selected[i]].SetTangent2Position(Handles.FreeMoveHandle(points[selected[i]].tangent2, Quaternion.identity, HandleUtility.GetHandleSize(points[selected[i]].tangent2) * 0.1f, Vector3.zero, Handles.CircleCap));
                    if (lastPos != points[selected[i]].tangent2)
                    {
                        change = true;
                    }
                }
            }
            return(change);
        }