AnimationTimeline.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. namespace Chronos
  3. {
  4. public class AnimationTimeline : ComponentTimeline<Animation>
  5. {
  6. public AnimationTimeline(Timeline timeline, Animation component) : base(timeline, component) { }
  7. private float _speed;
  8. /// <summary>
  9. /// The speed that is applied to the animation before time effects. Use this property instead of AnimationState.speed, which will be overwritten by the timeline at runtime.
  10. /// </summary>
  11. public float speed
  12. {
  13. get { return _speed; }
  14. set
  15. {
  16. _speed = value;
  17. AdjustProperties();
  18. }
  19. }
  20. public override void CopyProperties(Animation source)
  21. {
  22. float firstAnimationStateSpeed = 1;
  23. bool found = false;
  24. foreach (AnimationState animationState in source)
  25. {
  26. if (found && firstAnimationStateSpeed != animationState.speed)
  27. {
  28. Debug.LogWarning("Different animation speeds per state are not supported.");
  29. }
  30. firstAnimationStateSpeed = animationState.speed;
  31. found = true;
  32. }
  33. _speed = firstAnimationStateSpeed;
  34. }
  35. public override void AdjustProperties(float timeScale)
  36. {
  37. foreach (AnimationState state in component)
  38. {
  39. state.speed = speed * timeScale;
  40. }
  41. }
  42. }
  43. }