Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update CinemachineSplineDolly.cs & CinemachineSplineDollyEditor.cs * Converted PositionUnits to Property * Update `SplineContainerExtensions.cs` * Created `ConvertDistance` method & friends (Thanks Wybren van den Akker for helping with math) * Update `SplineContainerExtensions.cs` * Added `ArgumentOutOfRangeException`s to internal code (could theoretically be accessed if users use ASMREFs) * Update `CinemachineTrackedDolly.cs` (UpgradeToCm3) * Changed the order of upgrading. `m_Path` has to be done first, `CinemachineSplineDolly` needs it before its `PositionUnits` is set. * Update `SplineDollyCameraTest.cs` * Added Unit Tests for my changes * Added small comment why I use OnValidate the way that I do. * Update `SplineContainerExtensions.cs` * Added XML Documentation to new Conversion methods. * Update `SplineDollyCameraTest.cs` * `PositionUnits_DoesNotChangeCameraPosition_WhenPositionUnitsSame()` - Added additional asserts, not very important because as the code is now even just one should be enough. But still. * Update `SplineContainerExtensions.cs` * Fixed small error made in XML comments * Update `CinemachineSplineDollyEditor.cs` & `CinemachineSplineDolly.cs` * Moved my positionUnitsBackingfield change tracking from OnValidate to the custom editor. * refactor as struct with PropertyDrawer, include SplineCart, handle multi-select * Update CHANGELOG.md * Rename SplinePosition to SplineSettings, to break less API * add legacy support * propertydrawer layout tweak * handle prefabs better * clean up spline samples --------- Co-authored-by: Walter Hulsebos <walterhulsebos@outlook.com> Co-authored-by: Walter Hulsebos <77513543+Walter-Hulsebos@users.noreply.github.com>
- Loading branch information
1 parent
5593292
commit 4933236
Showing
15 changed files
with
496 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
com.unity.cinemachine/Editor/PropertyDrawers/SplineSettingsPropertyDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using UnityEditor; | ||
using UnityEngine.UIElements; | ||
using UnityEditor.UIElements; | ||
using UnityEngine.Splines; | ||
|
||
namespace Unity.Cinemachine.Editor | ||
{ | ||
[CustomPropertyDrawer(typeof(SplineSettings))] | ||
class SplineSettingsPropertyDrawer : PropertyDrawer | ||
{ | ||
public override VisualElement CreatePropertyGUI(SerializedProperty property) | ||
{ | ||
SplineSettings def = new (); | ||
var splineProp = property.FindPropertyRelative(() => def.Spline); | ||
var positionProp = property.FindPropertyRelative(() => def.Position); | ||
var unitsProp = property.FindPropertyRelative(() => def.Units); | ||
|
||
var ux = new VisualElement(); | ||
ux.Add(new PropertyField(splineProp)); | ||
var row = ux.AddChild(InspectorUtility.PropertyRow(positionProp, out var posField)); | ||
posField.style.flexGrow = 1; | ||
posField.style.flexBasis = 0; | ||
|
||
var initialUnits = (PathIndexUnit)unitsProp.enumValueIndex; | ||
var targets = property.serializedObject.targetObjects; | ||
for (int t = 0; t < targets.Length && initialUnits == (PathIndexUnit)unitsProp.enumValueIndex; ++t) | ||
if (new SerializedObject(targets[t]).FindProperty(unitsProp.propertyPath).enumValueIndex != (int)initialUnits) | ||
initialUnits = (PathIndexUnit)(-1); // mixed values | ||
|
||
var unitsField = row.Contents.AddChild(new EnumField( | ||
initialUnits) { style = { flexGrow = 2, flexBasis = 0 } }); | ||
unitsField.RegisterValueChangedCallback((evt) => | ||
{ | ||
var newUnits = (PathIndexUnit)evt.newValue; | ||
for (int i = 0; i < targets.Length; ++i) | ||
{ | ||
var o = new SerializedObject(targets[i]); | ||
var pU = o.FindProperty(unitsProp.propertyPath); | ||
var oldUnits = (PathIndexUnit)pU.enumValueIndex; | ||
if (oldUnits != newUnits) | ||
{ | ||
// Convert the position to the new units | ||
var pS = o.FindProperty(splineProp.propertyPath); | ||
var spline = pS.objectReferenceValue as SplineContainer; | ||
if (spline.IsValid()) | ||
{ | ||
var pP = o.FindProperty(positionProp.propertyPath); | ||
pP.floatValue = spline.Spline.ConvertIndexUnit(pP.floatValue, oldUnits, newUnits); | ||
} | ||
pU.enumValueIndex = (int)newUnits; | ||
o.ApplyModifiedProperties(); | ||
} | ||
} | ||
}); | ||
return ux; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.cinemachine/Editor/PropertyDrawers/SplineSettingsPropertyDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.