Skip to content

Commit

Permalink
Add default value handling when adding item from inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
glabute committed May 24, 2024
1 parent 5f07858 commit fd7e911
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions com.unity.cinemachine/Editor/Utility/SplineDataInspectorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static PropertyField CreateDataListField<T>(
GetSplineDelegate getSpline)
{
var sortMethod = splineData.GetType().GetMethod("ForceSort", BindingFlags.Instance | BindingFlags.NonPublic);
var setDataPointMethod = splineData.GetType().GetMethod("SetDataPoint", BindingFlags.Instance | BindingFlags.Public);

var pathUnitProp = splineDataProp.FindPropertyRelative("m_IndexUnit");
var arrayProp = splineDataProp.FindPropertyRelative("m_DataPoints");
Expand All @@ -77,6 +78,16 @@ public static PropertyField CreateDataListField<T>(
listView.showBoundCollectionSize = false;
listView.showAddRemoveFooter = true;
listView.showAlternatingRowBackgrounds = AlternatingRowBackground.None;

var button = list.Q<Button>("unity-list-view__add-button");
button.clicked += () =>
{
if (arrayProp.arraySize == 1)
{
setDataPointMethod.Invoke(splineData, new object[] { 0, new DataPoint<T> () { Value = splineData.DefaultValue } });
arrayProp.serializedObject.Update();
}
};
});

list.TrackPropertyValue(arrayProp, (p) =>
Expand Down

0 comments on commit fd7e911

Please sign in to comment.