예제 #1
0
        /// <summary>
        /// Handles the control logic for adding a point. This will draw a red line from the mouse position to the closest point along the
        /// curve
        /// </summary>
        /// <param name="spline">spline to handle control point logic for</param>
        protected void PointSelection(ISpline2DEditor spline)
        {
            float2 mouse = EditorInputAbstractions.MousePos2D();
            int    splineIndex;
            float2 createPoint = ClosestPointSelection(mouse, spline, out splineIndex);

            if (splineIndex != m_editNewPointIndex)
            {
                m_editNewPointIndex = splineIndex;
                Repaint(); // force refresh inspector
            }

            Handles.color = Color.red;
            Handles.DrawLine(
                new Vector3(createPoint.x, createPoint.y, 0f),
                new Vector3(mouse.x, mouse.y, 0f));

            if (EditorInputAbstractions.LeftClick() && spline is Object objSpline)
            {
                Undo.RecordObject(objSpline, "Insert Spline Point");
                EditorUtility.SetDirty(objSpline);

                float3 origin = m_sourceTrans.position;
                spline.InsertControlPoint(m_editNewPointIndex, mouse - origin.xy);

                SceneView.RepaintAll();
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the control logic for adding a point. This will draw a red line from the mouse position to the closest point along the
        /// curve
        /// </summary>
        /// <param name="spline">spline to handle control point logic for</param>
        protected void PointSelection(ISpline3DEditor spline)
        {
            int    splineIndex;
            float3 splinePoint, splineMousePoint;

            ClosestPointSelection(Event.current.mousePosition, spline, out splineIndex, out splinePoint, out splineMousePoint);

            if (splineIndex != m_editNewPointIndex)
            {
                m_editNewPointIndex = splineIndex;
                Repaint(); // force refresh inspector
            }

            Handles.color = Color.red;
            Handles.DrawLine(splinePoint, splineMousePoint);

            if (EditorInputAbstractions.LeftClick() && spline is Object objSpline)
            {
                Undo.RecordObject(objSpline, "Insert Spline Point");
                EditorUtility.SetDirty(objSpline);

                if ((m_editNewPointIndex == spline.ControlPointCount - 1 || spline.ControlPointCount == 1) &&
                    splinePoint.Equals(spline.GetControlPoint3DLocal(m_editNewPointIndex)))
                {
                    spline.AddControlPoint(splineMousePoint);
                }
                else
                {
                    spline.InsertControlPointWorldSpace(m_editNewPointIndex, splineMousePoint);
                }

                SceneView.RepaintAll();
            }
        }