diff --git a/com.unity.cinemachine/Editor/Editors/CinemachineSplineRollEditor.cs b/com.unity.cinemachine/Editor/Editors/CinemachineSplineRollEditor.cs index 9f8170ccf..2724a4f60 100644 --- a/com.unity.cinemachine/Editor/Editors/CinemachineSplineRollEditor.cs +++ b/com.unity.cinemachine/Editor/Editors/CinemachineSplineRollEditor.cs @@ -53,7 +53,7 @@ static void DrawSplineGizmo(CinemachineSplineRoll splineRoll, Color pathColor, f if (SplineGizmoCache.Instance == null || SplineGizmoCache.Instance.Mesh == null || SplineGizmoCache.Instance.Spline != spline.Spline - || SplineGizmoCache.Instance.SplineData != splineRoll.Roll + || SplineGizmoCache.Instance.RollData != splineRoll.Roll || SplineGizmoCache.Instance.Width != width || SplineGizmoCache.Instance.Resolution != resolution) { @@ -103,7 +103,7 @@ static void DrawSplineGizmo(CinemachineSplineRoll splineRoll, Color pathColor, f { Mesh = mesh, Spline = spline.Spline, - SplineData = splineRoll.Roll, + RollData = splineRoll.Roll, Width = width, Resolution = resolution }; @@ -122,7 +122,7 @@ static void DrawSplineGizmo(CinemachineSplineRoll splineRoll, Color pathColor, f class SplineGizmoCache { public Mesh Mesh; - public SplineData SplineData; + public SplineData RollData; public Spline Spline; public float Width; public int Resolution; @@ -135,22 +135,36 @@ static SplineGizmoCache() Instance = null; EditorSplineUtility.AfterSplineWasModified -= OnSplineChanged; EditorSplineUtility.AfterSplineWasModified += OnSplineChanged; - EditorSplineUtility.UnregisterSplineDataChanged(OnSplineDataChanged); - EditorSplineUtility.RegisterSplineDataChanged(OnSplineDataChanged); + EditorSplineUtility.UnregisterSplineDataChanged(OnSplineDataChanged); + EditorSplineUtility.RegisterSplineDataChanged(OnSplineDataChanged); } static void OnSplineChanged(Spline spline) { if (Instance != null && spline == Instance.Spline) Instance = null; } - static void OnSplineDataChanged(SplineData data) + static void OnSplineDataChanged(SplineData data) { - if (Instance != null && data == Instance.SplineData) + if (Instance != null && data == Instance.RollData) Instance = null; } } } + [CustomPropertyDrawer(typeof(DataPoint))] + class CinemachineLookAtDataOnSplineItemPropertyDrawer : PropertyDrawer + { + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + var ux = new VisualElement { style = { flexDirection = FlexDirection.Row }}; + ux.Add(new InspectorUtility.CompactPropertyField(property.FindPropertyRelative("m_Index"))); + + var def = new CinemachineSplineRoll.RollData(); + var valueProp = property.FindPropertyRelative("m_Value"); + ux.Add(new InspectorUtility.CompactPropertyField(valueProp.FindPropertyRelative(() => def.Value)) { style = { marginLeft = 3 }}); + return ux; + } + } [EditorTool("Spline Roll Tool", typeof(CinemachineSplineRoll))] sealed class SplineRollTool : EditorTool, IDrawSelectedHandles @@ -190,7 +204,7 @@ public override void OnToolGUI(EditorWindow window) if (!GetTargets(out var splineData, out var spline)) return; - Undo.RecordObject(splineData, "Modifying Roll SplineData"); + Undo.RecordObject(splineData, "Modifying Roll RollData"); var color = Handles.selectedColor; if (!Active) color.a = k_UnselectedAlpha; @@ -219,7 +233,7 @@ public void OnDrawHandles() // inverse pre-calculation optimization readonly Quaternion m_DefaultHandleOrientation = Quaternion.Euler(270, 0, 0); readonly Quaternion m_DefaultHandleOrientationInverse = Quaternion.Euler(90, 0, 0); - bool DrawRollDataPoints(NativeSpline spline, SplineData splineData, bool enabled) + bool DrawRollDataPoints(NativeSpline spline, SplineData splineData, bool enabled) { var inUse = false; for (var r = 0; r < splineData.Count; ++r) diff --git a/com.unity.cinemachine/Editor/Upgrader/UpgradeObjectToCm3.cs b/com.unity.cinemachine/Editor/Upgrader/UpgradeObjectToCm3.cs index 729e89100..8247bad8d 100644 --- a/com.unity.cinemachine/Editor/Upgrader/UpgradeObjectToCm3.cs +++ b/com.unity.cinemachine/Editor/Upgrader/UpgradeObjectToCm3.cs @@ -701,7 +701,7 @@ static void UpgradePath(CinemachinePathBase pathBase) spline = Undo.AddComponent(go); var splineRoll = Undo.AddComponent(go); - splineRoll.Roll = new SplineData(); + splineRoll.Roll = new SplineData(); Undo.RecordObject(pathBase, "Upgrader: disable obsolete"); pathBase.enabled = false; @@ -721,7 +721,7 @@ static void UpgradePath(CinemachinePathBase pathBase) TangentIn = -waypoints[i].tangent, TangentOut = waypoints[i].tangent, }); - splineRoll.Roll.Add(new DataPoint(i, waypoints[i].roll)); + splineRoll.Roll.Add(new DataPoint(i, waypoints[i].roll)); } break; } @@ -740,7 +740,7 @@ static void UpgradePath(CinemachinePathBase pathBase) TangentIn = -tangent, TangentOut = tangent, }); - splineRoll.Roll.Add(new DataPoint(i, waypoints[i].roll)); + splineRoll.Roll.Add(new DataPoint(i, waypoints[i].roll)); } break; } diff --git a/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs b/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs index 32b370f53..8a49946cd 100644 --- a/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs +++ b/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs @@ -770,10 +770,11 @@ public CompactPropertyField(SerializedProperty property) : this(property, proper public CompactPropertyField(SerializedProperty property, string label, float minLabelWidth = 0) { style.flexDirection = FlexDirection.Row; + style.flexGrow = 1; if (!string.IsNullOrEmpty(label)) Label = AddChild(this, new Label(label) { tooltip = property?.tooltip, style = { alignSelf = Align.Center, minWidth = minLabelWidth }}); - Field = AddChild(this, new PropertyField(property, "") { style = { flexGrow = 1, flexBasis = 10 } }); + Field = AddChild(this, new PropertyField(property, "") { style = { flexGrow = 1, flexBasis = 20 } }); if (Label != null) AddDelayedFriendlyPropertyDragger(Label, property, Field); } diff --git a/com.unity.cinemachine/Runtime/Behaviours/CinemachineSplineRoll.cs b/com.unity.cinemachine/Runtime/Behaviours/CinemachineSplineRoll.cs index dd0298e4a..8e01da234 100644 --- a/com.unity.cinemachine/Runtime/Behaviours/CinemachineSplineRoll.cs +++ b/com.unity.cinemachine/Runtime/Behaviours/CinemachineSplineRoll.cs @@ -17,6 +17,35 @@ namespace Unity.Cinemachine [HelpURL(Documentation.BaseURL + "manual/CinemachineSplineRoll.html")] public class CinemachineSplineRoll : MonoBehaviour { + /// Structure to hold roll value for a specific location on the track. + [Serializable] + public struct RollData + { + /// + /// Roll (in degrees) around the forward direction for specific location on the track. + /// When placed on a SplineContainer, this is going to be a global override that affects all vcams using the Spline. + /// When placed on a vcam, this is going to be a local override that only affects that vcam. + /// + public float Value; + + /// Implicit conversion to float + /// The RollData setting to convert. + /// The value of the RollData setting. + public static implicit operator float(RollData roll) => roll.Value; + + /// Implicit conversion from float + /// The value with which to initialize the RollData setting. + /// A new RollData setting with the given value. + public static implicit operator RollData(float roll) => new () { Value = roll }; + } + + /// Interpolator for the RollData + public struct LerpRollData : IInterpolator + { + /// + public RollData Interpolate(RollData a, RollData b, float t) => new() { Value = Mathf.Lerp(a.Value, b.Value, t) }; + } + /// /// Roll (in degrees) around the forward direction for specific location on the track. /// When placed on a SplineContainer, this is going to be a global override that affects all vcams using the Spline. @@ -26,7 +55,7 @@ public class CinemachineSplineRoll : MonoBehaviour [Tooltip("Roll (in degrees) around the forward direction for specific location on the track.\n" + "- When placed on a SplineContainer, this is going to be a global override that affects all vcams using the Spline.\n" + "- When placed on a vcam, this is going to be a local override that only affects that vcam.")] - public SplineData Roll; + public SplineData Roll; #if UNITY_EDITOR // Only needed for drawing the gizmo diff --git a/com.unity.cinemachine/Runtime/Core/SplineContainerExtensions.cs b/com.unity.cinemachine/Runtime/Core/SplineContainerExtensions.cs index 9a179413b..71f47b754 100644 --- a/com.unity.cinemachine/Runtime/Core/SplineContainerExtensions.cs +++ b/com.unity.cinemachine/Runtime/Core/SplineContainerExtensions.cs @@ -64,7 +64,7 @@ public static bool LocalEvaluateSplineWithRoll( if (roll != null && roll.enabled) { float rollValue = roll.Roll.Evaluate(spline.Spline, tNormalized, - PathIndexUnit.Normalized, new UnityEngine.Splines.Interpolators.LerpFloat()); + PathIndexUnit.Normalized, new CinemachineSplineRoll.LerpRollData()); rotation = Quaternion.AngleAxis(-rollValue, fwd) * rotation; } return true;