RuntimeClip.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. namespace UnityEngine.Timeline
  4. {
  5. // The RuntimeClip wraps a single clip in an instantiated sequence.
  6. // It supports the IInterval interface so that it can be stored in the interval tree
  7. // It is this class that is returned by an interval tree query.
  8. class RuntimeClip : RuntimeClipBase
  9. {
  10. TimelineClip m_Clip;
  11. Playable m_Playable;
  12. Playable m_ParentMixer;
  13. public override double start
  14. {
  15. get { return m_Clip.extrapolatedStart; }
  16. }
  17. public override double duration
  18. {
  19. get { return m_Clip.extrapolatedDuration; }
  20. }
  21. public RuntimeClip(TimelineClip clip, Playable clipPlayable, Playable parentMixer)
  22. {
  23. Create(clip, clipPlayable, parentMixer);
  24. }
  25. void Create(TimelineClip clip, Playable clipPlayable, Playable parentMixer)
  26. {
  27. m_Clip = clip;
  28. m_Playable = clipPlayable;
  29. m_ParentMixer = parentMixer;
  30. clipPlayable.Pause();
  31. }
  32. public TimelineClip clip
  33. {
  34. get { return m_Clip; }
  35. }
  36. public Playable mixer
  37. {
  38. get { return m_ParentMixer; }
  39. }
  40. public Playable playable
  41. {
  42. get { return m_Playable; }
  43. }
  44. public override bool enable
  45. {
  46. set
  47. {
  48. if (value && m_Playable.GetPlayState() != PlayState.Playing)
  49. {
  50. m_Playable.Play();
  51. SetTime(m_Clip.clipIn);
  52. }
  53. else if (!value && m_Playable.GetPlayState() != PlayState.Paused)
  54. {
  55. m_Playable.Pause();
  56. if (m_ParentMixer.IsValid())
  57. m_ParentMixer.SetInputWeight(m_Playable, 0.0f);
  58. }
  59. }
  60. }
  61. public void SetTime(double time)
  62. {
  63. m_Playable.SetTime(time);
  64. }
  65. public void SetDuration(double duration)
  66. {
  67. m_Playable.SetDuration(duration);
  68. }
  69. public override void EvaluateAt(double localTime, FrameData frameData)
  70. {
  71. enable = true;
  72. float weight = 1.0f;
  73. if (clip.IsPreExtrapolatedTime(localTime))
  74. weight = clip.EvaluateMixIn((float)clip.start);
  75. else if (clip.IsPostExtrapolatedTime(localTime))
  76. weight = clip.EvaluateMixOut((float)clip.end);
  77. else
  78. weight = clip.EvaluateMixIn(localTime) * clip.EvaluateMixOut(localTime);
  79. if (mixer.IsValid())
  80. mixer.SetInputWeight(playable, weight);
  81. // localTime of the sequence to localtime of the clip
  82. double clipTime = clip.ToLocalTime(localTime);
  83. if (clipTime >= -DiscreteTime.tickValue/2 )
  84. {
  85. SetTime(clipTime);
  86. }
  87. SetDuration(clip.extrapolatedDuration);
  88. }
  89. public override void Reset()
  90. {
  91. SetTime(m_Clip.clipIn);
  92. }
  93. }
  94. }