Example #1
0
    public override void OnInspectorGUI()
    {
        if (spline == null)
        {
            return;
        }

        EditorGUI.BeginChangeCheck();
        spline.DrawGizmo = EditorGUILayout.Toggle("Draw Gizmo", spline.DrawGizmo);

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop:", spline.Loop);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Loop");
            spline.Loop = loop;
            EditorUtility.SetDirty(spline);
        }

        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Point:", spline.GetControlPoint(spline.selected_elt));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            spline.SetControlPoint(spline.selected_elt, point);
            EditorUtility.SetDirty(spline);
        }
        if (spline.selected_elt != 0)
        {
            EditorGUI.BeginChangeCheck();
            point = EditorGUILayout.Vector3Field("Left Handle:", spline.GetHandle(spline.selected_elt, true));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Left Handle");
                spline.SetHandle(spline.selected_elt, true, point);
                EditorUtility.SetDirty(spline);
            }
        }
        if (spline.selected_elt < spline.GetCurveCount())
        {
            EditorGUI.BeginChangeCheck();
            point = EditorGUILayout.Vector3Field("Right Handle:", spline.GetHandle(spline.selected_elt, false));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Left Handle");
                spline.SetHandle(spline.selected_elt, false, point);
                EditorUtility.SetDirty(spline);
            }
        }

        GUILayout.Label("Add Curve At:");
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Beginning"))
        {
            Undo.RecordObject(spline, "Add Curve at Beginning");
            spline.AddCurveBeginning();
            EditorUtility.SetDirty(spline);
        }
        if (GUILayout.Button("End"))
        {
            Undo.RecordObject(spline, "Add Curve at End");
            spline.AddCurve();
            EditorUtility.SetDirty(spline);
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Label("Subdivide Curve:");
        EditorGUILayout.BeginHorizontal();
        if ((spline.selected_elt != 0 || spline.Loop) && GUILayout.Button("Left"))
        {
            Undo.RecordObject(spline, "Subdivide Curve Left");
            spline.SubdivideCurve(spline.selected_elt);
            EditorUtility.SetDirty(spline);
        }
        if ((spline.selected_elt < spline.GetCurveCount() || spline.Loop) && GUILayout.Button("Right"))
        {
            Undo.RecordObject(spline, "Subdivide Curve Right");
            spline.SubdivideCurve(spline.selected_elt + 1);
            EditorUtility.SetDirty(spline);
        }
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Remove Curve"))
        {
            Undo.RecordObject(spline, "Remove Curve");
            spline.RemoveCurve(spline.selected_elt);
            EditorUtility.SetDirty(spline);
        }

        if ((spline.selected_elt != 0 && spline.selected_elt < spline.GetControlPointCount() - 1) || spline.Loop)
        {
            EditorGUI.BeginChangeCheck();
            Spline.HandleConstraint nw = (Spline.HandleConstraint)EditorGUILayout.EnumPopup("Handle Constraint: ", spline.GetConstraint(spline.selected_elt));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Set Constraint");
                spline.SetConstraint(spline.selected_elt, nw);
                if (spline.selected_elt == spline.GetControlPointCount() - 1)
                {
                    spline.selected_elt = 0;
                }
                EditorUtility.SetDirty(spline);
            }
        }
    }