TransformTimeline.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. namespace Chronos
  3. {
  4. public class TransformTimeline : RecorderTimeline<Transform, TransformTimeline.Snapshot>
  5. {
  6. // Scale is disabled by default because it usually doesn't change and
  7. // would otherwise take more memory. Feel free to uncomment the lines
  8. // below if you need to record it.
  9. public struct Snapshot
  10. {
  11. public Vector3 position;
  12. public Quaternion rotation;
  13. //public Vector3 scale;
  14. public static Snapshot Lerp(Snapshot from, Snapshot to, float t)
  15. {
  16. return new Snapshot()
  17. {
  18. position = Vector3.Lerp(from.position, to.position, t),
  19. rotation = Quaternion.Lerp(from.rotation, to.rotation, t),
  20. //scale = Vector3.Lerp(from.scale, to.scale, t)
  21. };
  22. }
  23. }
  24. public TransformTimeline(Timeline timeline, Transform component) : base(timeline, component) { }
  25. protected override Snapshot LerpSnapshots(Snapshot from, Snapshot to, float t)
  26. {
  27. return Snapshot.Lerp(from, to, t);
  28. }
  29. protected override Snapshot CopySnapshot()
  30. {
  31. return new Snapshot()
  32. {
  33. position = component.position,
  34. rotation = component.rotation,
  35. //scale = component.localScale
  36. };
  37. }
  38. protected override void ApplySnapshot(Snapshot snapshot)
  39. {
  40. component.position = snapshot.position;
  41. component.rotation = snapshot.rotation;
  42. //component.localScale = snapshot.scale;
  43. }
  44. }
  45. }