Skip to content

Commit

Permalink
Add a save button to spline editor
Browse files Browse the repository at this point in the history
This drastically improves editor performance when modifying the spline
  • Loading branch information
BocuD committed Jul 10, 2021
1 parent 05ef593 commit b3fe238
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions CatmullRomSpline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class CatmullRomSpline : UdonSharpBehaviour
[HideInInspector] public bool drawTangents;
[HideInInspector] public float normalExtrusion;
[HideInInspector] public float tangentExtrusion;

[HideInInspector] public bool save;

public Transform[] controlPointTransforms;

Expand Down Expand Up @@ -187,6 +189,14 @@ private void GenerateSplinePoints()
normals[currentPoint * resolution + tesselatedPoint] = pointNormal;
}
}

#if !COMPILER_UDONSHARP && UNITY_EDITOR
if (save)
{
this.ApplyProxyModifications();
save = false;
}
#endif
}
#region CALCULATE POINTS
//Calculates curve position at t[0, 1]
Expand Down Expand Up @@ -228,6 +238,10 @@ public Vector3 NormalFromTangent(Vector3 tangent)
/// <param name="newControlPoints">New transform array</param>
public void UpdateControlPointTransforms(Transform[] newControlPoints)
{
#if !COMPILER_UDONSHARP && UNITY_EDITOR
this.UpdateProxy();
#endif

if (newControlPoints == null || newControlPoints.Length <= 0)
{
Debug.LogError("Invalid control points");
Expand All @@ -247,6 +261,10 @@ public void UpdateControlPointTransforms(Transform[] newControlPoints)
/// <param name="newControlPoints">New vector3 array</param>
public void UpdateControlPointVectors(Vector3[] newControlPoints)
{
#if !COMPILER_UDONSHARP && UNITY_EDITOR
this.UpdateProxy();
#endif

if (newControlPoints == null || newControlPoints.Length <= 0)
{
Debug.LogError("Invalid control points");
Expand Down Expand Up @@ -372,8 +390,8 @@ public override void OnInspectorGUI()
tangentExtrusion = EditorGUILayout.Slider("Tangent length", tangentExtrusion, 0, 3);
}

//bool updatePositions = GUILayout.Button("Update spline positions");

bool save = GUILayout.Button("Save Spline Changes");
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(catmullRomSpline, "Modify CatmullRomSpline values");
Expand All @@ -389,6 +407,8 @@ public override void OnInspectorGUI()
catmullRomSpline.normalExtrusion = normalExtrusion;
catmullRomSpline.tangentExtrusion = tangentExtrusion;

catmullRomSpline.save = save;

// else
// {
// catmullRomSpline.SetupCatmullRom(controlPoints, resolution, closedLoop);
Expand Down

0 comments on commit b3fe238

Please sign in to comment.