Esempio n. 1
0
        private JunctionHandle.Result DrawJunctionHandle(SplineRenderer renderer, Vector3 position, float scale)
        {
            Handles.DrawCapFunction dcf = Handles.CircleCap;
            float size = HandleUtility.GetHandleSize(position) * 2.0f * scale * m_pointSizeConst;

            Vector2 guiPosition = HandleUtility.WorldToGUIPoint(position);

            if (Vector2.Distance(guiPosition, Event.current.mousePosition) > 15 * renderer.PointSize * scale || IsControlPointDrag || Event.current.alt)
            {
                size *= 0;
            }

            JunctionHandle.Result result = JunctionHandle.GUI(position, Quaternion.LookRotation(Camera.current.transform.forward),
                                                              size * renderer.PointSize, size * renderer.PointSize, dcf, renderer.SelectionColor);
            return(result);
        }
Esempio n. 2
0
        private void DrawSplinePoint(ref SplineEditorEventArgs args, ref SplineEditorEvent evnt, SplineRenderer splineRenderer, SplineBase spline, int j)
        {
            int mode = spline.GetPointMode(j);

            if (mode >= 0 && mode < splineRenderer.ControlPointColors.Length)
            {
                Handles.color = splineRenderer.ControlPointColors[mode];
            }

            int controlPointsCount = spline.GetCtrlPointsCount(j);

            for (int k = 0; k < controlPointsCount; ++k)
            {
                int scale = 1;
                if (!splineRenderer.IsControlPointVisible(j, k))
                {
                    scale = 0;
                }

                Vector3 ctrlPosition = spline.GetCtrlPointPosition(j, k);
                SplinePointHandle.Result ctrlPointDragResult = DrawPointHandle(splineRenderer, ctrlPosition, scale, true);
                if (ctrlPointDragResult == SplinePointHandle.Result.Drag)
                {
                    if (evnt == SplineEditorEvent.None)
                    {
                        args = new SplineEditorEventArgs(spline, j, k);
                        evnt = SplineEditorEvent.SplineCtrlPointDrag;
                    }
                }
                if (ctrlPointDragResult == SplinePointHandle.Result.EndDrag)
                {
                    if (evnt == SplineEditorEvent.None)
                    {
                        args = new SplineEditorEventArgs(spline, j, k);
                        evnt = SplineEditorEvent.SplineCtrlPointDrop;
                    }
                }
            }

            float dragHandleScale = 1;

            if (m_draggingDragPointHandle && spline == DragSpline && DragPointIndex == j)
            {
                dragHandleScale = 0;
            }

            JunctionBase junction = spline.GetJunction(j);

            if (junction != null && junction != NewJunction)
            {
                bool drawSplinePoint = junction == null || spline == junction.GetSpline(0) && j == junction.GetSplinePointIndex(0);
                if (drawSplinePoint)
                {
                    dragHandleScale = 1.5f;
                }
                else
                {
                    dragHandleScale = 0;
                }
            }


            Handles.color = splineRenderer.SplinePointColor;
            Vector3 position = spline.GetPointPosition(j);

            SplinePointHandle.Result dragResult = DrawDragHandle(splineRenderer, position, dragHandleScale, DragSpline == null);
            if (dragResult == SplinePointHandle.Result.Drag)
            {
                if (evnt == SplineEditorEvent.None)
                {
                    args = new SplineEditorEventArgs(spline, j);
                    evnt = SplineEditorEvent.SplinePointDrag;
                }
            }
            else if (dragResult == SplinePointHandle.Result.EndDrag)
            {
                if (evnt == SplineEditorEvent.None)
                {
                    args = new SplineEditorEventArgs(spline, j);
                    evnt = SplineEditorEvent.SplinePointDrop;
                }
            }
            else if (dragResult == SplinePointHandle.Result.PointerOver)
            {
                m_pointerOverSpline           = spline;
                m_pointerOverSplinePointIndex = j;
                m_pointerOver = true;
            }

            if (junction != null && junction != NewJunction)
            {
                Handles.color = splineRenderer.JunctionColor;
                JunctionHandle.Result junctionResult = DrawJunctionHandle(splineRenderer, junction.transform.position, 1);
                if (junctionResult == JunctionHandle.Result.Click)
                {
                    evnt = SplineEditorEvent.JunctionClick;
                    args = new SplineEditorEventArgs(junction);
                }
                else if (junctionResult == JunctionHandle.Result.Drag)
                {
                    evnt = SplineEditorEvent.JunctionDrag;
                    args = new SplineEditorEventArgs(junction);
                }
            }

            Handles.color = splineRenderer.SplinePointColor;
            SplinePointHandle.Result result = DrawPointHandle(splineRenderer, position, 1, false);
            if (result == SplinePointHandle.Result.EndDrag)
            {
                m_draggingDragPointHandle = false;
                if (evnt == SplineEditorEvent.None)
                {
                    args = new SplineEditorEventArgs(spline, j);
                    evnt = SplineEditorEvent.SplinePointCreatorDrop;
                }
            }
            else if (result == SplinePointHandle.Result.Drag)
            {
                m_draggingDragPointHandle = true;
                if (evnt == SplineEditorEvent.None)
                {
                    args = new SplineEditorEventArgs(spline, j);
                    evnt = SplineEditorEvent.SplinePointCreatorDrag;
                }
            }
        }