Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TimeDilationMixerBehaviour.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. using UnityEngine.Timeline;
  4. namespace Timeline.Samples
  5. {
  6. // A track mixer behaviour that modifies the timeScale. This affects how fast the game plays back
  7. public class TimeDilationMixerBehaviour : PlayableBehaviour
  8. {
  9. private float m_DefaultTimeScale = 1;
  10. // Called every frame that the timeline is Evaluated.
  11. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
  12. {
  13. int inputCount = playable.GetInputCount();
  14. float timeScale = 0f;
  15. float totalWeight = 0f;
  16. // blend clips together
  17. for (int i = 0; i < inputCount; i++)
  18. {
  19. float inputWeight = playable.GetInputWeight(i);
  20. ScriptPlayable<TimeDilationBehaviour> playableInput = (ScriptPlayable<TimeDilationBehaviour>)playable.GetInput(i);
  21. TimeDilationBehaviour input = playableInput.GetBehaviour();
  22. timeScale += inputWeight * input.timeScale;
  23. totalWeight += inputWeight;
  24. }
  25. // blend to/from the default timeline
  26. Time.timeScale = Mathf.Max(0.0001f, Mathf.Lerp(m_DefaultTimeScale, timeScale, Mathf.Clamp01(totalWeight)));
  27. }
  28. // Called when the playable graph is created, typically when the timeline is played.
  29. public override void OnPlayableCreate(Playable playable)
  30. {
  31. m_DefaultTimeScale = Time.timeScale;
  32. }
  33. // Called when the playable is destroyed, typically when the timeline stops.
  34. public override void OnPlayableDestroy(Playable playable)
  35. {
  36. Time.timeScale = m_DefaultTimeScale;
  37. }
  38. }
  39. }