using UnityEngine;
namespace Cinemachine
{
///
/// A definition of an impulse signal that gets propagated to listeners
///
[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
[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")]
public AnimationCurve m_XCurve;
/// The raw signal shape along the Y axis
[Tooltip("The raw signal shape along the Y axis")]
public AnimationCurve m_YCurve;
/// The raw signal shape along the Z axis
[Tooltip("The raw signal shape along the Z axis")]
public AnimationCurve m_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(m_XCurve),
Mathf.Max(AxisDuration(m_YCurve), AxisDuration(m_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(m_XCurve, timeSinceSignalStart),
AxisValue(m_YCurve, timeSinceSignalStart),
AxisValue(m_ZCurve, timeSinceSignalStart));
}
float AxisValue(AnimationCurve axis, float time)
{
if (axis == null || axis.length == 0)
return 0;
return axis.Evaluate(time);
}
}
}