Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuntimeClip.cs 3.7KB

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