Exemple #1
0
    private Vector3 ShowPoint(int index)
    {
        Vector3    point       = handleTransform.TransformPoint(spline.GetControlPoint(index));
        Quaternion Orientation = Quaternion.identity;

        //Quaternion pointOrientation = spline.GetControlPointOrientation(index);
        handleRotation = Tools.pivotRotation == PivotRotation.Local ?
                         spline.GetControlPointOrientation(index) : Quaternion.identity;
        //if (spline.transform.hasChanged)
        //{
        //    spline._editModeUpdate();
        //}
        float size = HandleUtility.GetHandleSize(point);

        if (index == 0)
        {
            size *= 2f;
        }
        Handles.color = modeColors[(int)spline.GetControlPointMode(index)];
        if (index % 3 == 0)
        {
            Handles.color = Color.green;
        }

        if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotHandleCap))
        {
            selectedIndex = index;
            Repaint();
        }
        Handles.color = Color.white;

        if (selectedIndex == index)
        {
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, handleRotation);
            if (selectedIndex == spline.returnLastIndex())
            {
                Orientation = Handles.DoRotationHandle(handleRotation, point);
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Point");
                spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
                if (Orientation != Quaternion.identity)
                {
                    Undo.RecordObject(spline, "Orientation of Path Section Changed");
                    spline.SetControlPointsRotation(index, Orientation);
                }
                //Debug.Log(index);
                EditorUtility.SetDirty(spline);
            }
        }
        return(point);
    }