Ejemplo n.º 1
0
    private void DrawSelectedPointInspector()
    {
        GUISpace();

        GUILayout.Label("Selected Point");

        GUILayout.BeginHorizontal();
        // Select next/previous point/anchor
        if (GUILayout.Button("Previous") && selectedIndex - 1 >= 0)
        {
            selectedIndex--;
        }
        if (GUILayout.Button("Next") && selectedIndex + 1 < spline.PointCount)
        {
            selectedIndex++;
        }

        // Deselect points
        if (GUILayout.Button("Deselect"))
        {
            selectedIndex = -1;
            return;
        }
        GUILayout.EndHorizontal();

        // Position field
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetPoint(selectedIndex, point);
        }

        // Control mode dropdown
        EditorGUI.BeginChangeCheck();
        BezierPointMode mode = (BezierPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////// EO GET POINT //

    private void EnforceMode(int index)
    {
        int modeIndex = (index + 1) / 3;

        BezierPointMode mode = modes[modeIndex];

        // Skip enforcing for FREE points and START/END points
        if (mode == BezierPointMode.Free || modeIndex == 0 || modeIndex == modes.Length - 1)
        {
            return;
        }

        // Get indexes
        int pointIndex = modeIndex * 3;
        int holdingIndex;
        int enforcedIndex;

        if (index <= pointIndex)
        {
            holdingIndex  = pointIndex - 1;
            enforcedIndex = pointIndex + 1;
        }
        else
        {
            holdingIndex  = pointIndex + 1;
            enforcedIndex = pointIndex - 1;
        }


        Vector3 point           = points[pointIndex];
        Vector3 enforcedTangent = point - points[holdingIndex];

        // Keep length of enforced anchor
        // in case of Aligned mode
        if (mode == BezierPointMode.Aligned)
        {
            enforcedTangent = enforcedTangent.normalized * Vector3.Distance(point, points[enforcedIndex]);
        }
        points[enforcedIndex] = point + enforcedTangent;
    }
Ejemplo n.º 3
0
 public void SetPointMode(int index, BezierPointMode mode)
 {
     modes[(index + 1) / 3] = mode;
     EnforceMode(index);
     BakeSpline(bakedSteps);
 }