예제 #1
0
        private bool BeginDragSplinePoint()
        {
            Vector3 position;

            if (GetPositionOnDragPlane(ScreenPointToRay(MousePosition), out position))
            {
                Vector3     offset = position - m_dragSpline.GetPointPosition(m_dragPointIndex);
                const float s      = 0.1f;
                if (offset.magnitude > HandleSize(m_beginDragPosition) * s)
                {
                    JunctionBase junction = m_dragSpline.GetJunction(m_dragPointIndex);

                    if (m_dragPointIndex == 0 && junction == null)
                    {
                        m_dragSpline.Prepend(position);

                        GameObject splinePoint = m_dragSpline.GetPoint(0);

                        RegisterCreatedObjectUndo(splinePoint, "BH.S3.Prepend");
                        SetTransformParentUndo(splinePoint.transform, splinePoint.transform.parent, "BH.S3.Prepend");
                    }
                    else if (m_dragPointIndex == m_dragSpline.PointsCount - 1 && junction == null)
                    {
                        m_dragSpline.Append(position);
                        m_dragPointIndex = m_dragSpline.PointsCount - 1;
                        RegisterCreatedObjectUndo(m_dragSpline.GetPoint(m_dragPointIndex), "BH.S3.Append");
                    }
                    else
                    {
                        Vector3 dir;
                        if (m_dragSpline.CurveCount == m_dragPointIndex)
                        {
                            dir = m_dragSpline.GetDirection(1.0f);
                        }
                        else
                        {
                            dir = m_dragSpline.GetDirection(0, m_dragPointIndex);
                        }

                        bool isOut           = Mathf.Sign(Vector3.Dot(offset.normalized, dir)) >= 0;
                        int  connectionIndex = m_dragSpline.CreateBranch(m_dragPointIndex, isOut);

                        junction = m_dragSpline.GetJunction(m_dragPointIndex);

                        m_dragSpline = junction.GetSpline(connectionIndex);
                        RegisterCreatedObjectUndo(m_dragSpline.gameObject, "BH.S3.Branch");

                        if (junction.ConnectionsCount == 2)
                        {
                            m_newJunction = junction;
                            RegisterCreatedObjectUndo(junction.gameObject, "BH.S3.Branch");
                        }

                        m_splines = m_splines.Add(m_dragSpline);

                        SplineRenderer splineRenderer = m_dragSpline.GetComponent <SplineRenderer>();
                        m_splineRenderers = m_splineRenderers.Add(splineRenderer);

                        if (splineRenderer != null)
                        {
                            splineRenderer.IsSelected = true;
                        }

                        m_dragPointIndex = isOut ? 1 : 0;
                    }

                    return(true);
                }
            }
            return(false);
        }