CinemachineFixedSignal.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. namespace Cinemachine
  3. {
  4. /// <summary>
  5. /// A definition of an impulse signal that gets propagated to listeners
  6. /// </summary>
  7. [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
  8. [HelpURL(Documentation.BaseURL + "manual/CinemachineImpulseFixedSignals.html")]
  9. public class CinemachineFixedSignal : SignalSourceAsset
  10. {
  11. /// <summary>The raw signal shape along the X axis</summary>
  12. [Tooltip("The raw signal shape along the X axis")]
  13. public AnimationCurve m_XCurve;
  14. /// <summary>The raw signal shape along the Y axis</summary>
  15. [Tooltip("The raw signal shape along the Y axis")]
  16. public AnimationCurve m_YCurve;
  17. /// <summary>The raw signal shape along the Z axis</summary>
  18. [Tooltip("The raw signal shape along the Z axis")]
  19. public AnimationCurve m_ZCurve;
  20. /// <summary>
  21. /// Returns the length on seconds of the signal.
  22. /// Returns 0 for signals of indeterminate length.
  23. /// </summary>
  24. public override float SignalDuration
  25. {
  26. get
  27. {
  28. return Mathf.Max(
  29. AxisDuration(m_XCurve),
  30. Mathf.Max(AxisDuration(m_YCurve), AxisDuration(m_ZCurve)));
  31. }
  32. }
  33. float AxisDuration(AnimationCurve axis)
  34. {
  35. float duration = 0;
  36. if (axis != null && axis.length > 1)
  37. {
  38. float start = axis[0].time;
  39. duration = axis[axis.length-1].time - start;
  40. }
  41. return duration;
  42. }
  43. /// <summary>Get the raw signal at this time</summary>
  44. /// <param name="timeSinceSignalStart">The time since in seconds since the start of the signal</param>
  45. /// <param name="pos">The position impulse signal</param>
  46. /// <param name="rot">The rotation impulse signal</param>
  47. public override void GetSignal(float timeSinceSignalStart, out Vector3 pos, out Quaternion rot)
  48. {
  49. rot = Quaternion.identity;
  50. pos = new Vector3(
  51. AxisValue(m_XCurve, timeSinceSignalStart),
  52. AxisValue(m_YCurve, timeSinceSignalStart),
  53. AxisValue(m_ZCurve, timeSinceSignalStart));
  54. }
  55. float AxisValue(AnimationCurve axis, float time)
  56. {
  57. if (axis == null || axis.length == 0)
  58. return 0;
  59. return axis.Evaluate(time);
  60. }
  61. }
  62. }