using UnityEngine; using UnityEngine.Serialization; namespace Unity.Cinemachine { /// /// A definition of an impulse signal that gets propagated to listeners /// [HelpURL(Documentation.BaseURL + "manual/CinemachineImpulseFixedSignals.html")] public class CinemachineFixedSignal : SignalSourceAsset { /// The raw signal shape along the X axis [Tooltip("The raw signal shape along the X axis")] [FormerlySerializedAs("m_XCurve")] public AnimationCurve XCurve; /// The raw signal shape along the Y axis [Tooltip("The raw signal shape along the Y axis")] [FormerlySerializedAs("m_YCurve")] public AnimationCurve YCurve; /// The raw signal shape along the Z axis [Tooltip("The raw signal shape along the Z axis")] [FormerlySerializedAs("m_ZCurve")] public AnimationCurve ZCurve; /// /// Returns the length on seconds of the signal. /// Returns 0 for signals of indeterminate length. /// public override float SignalDuration { get { return Mathf.Max( AxisDuration(XCurve), Mathf.Max(AxisDuration(YCurve), AxisDuration(ZCurve))); } } float AxisDuration(AnimationCurve axis) { float duration = 0; if (axis != null && axis.length > 1) { float start = axis[0].time; duration = axis[axis.length-1].time - start; } return duration; } /// Get the raw signal at this time /// The time since in seconds since the start of the signal /// The position impulse signal /// The rotation impulse signal public override void GetSignal(float timeSinceSignalStart, out Vector3 pos, out Quaternion rot) { rot = Quaternion.identity; pos = new Vector3( AxisValue(XCurve, timeSinceSignalStart), AxisValue(YCurve, timeSinceSignalStart), AxisValue(ZCurve, timeSinceSignalStart)); } float AxisValue(AnimationCurve axis, float time) { if (axis == null || axis.length == 0) return 0; return axis.Evaluate(time); } } }