UnityMotionAdapter.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Unity.Jobs;
  2. using Unity.Mathematics;
  3. using UnityEngine;
  4. using LitMotion;
  5. using LitMotion.Adapters;
  6. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Vector2, NoOptions, Vector2MotionAdapter>))]
  7. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Vector3, NoOptions, Vector3MotionAdapter>))]
  8. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Vector4, NoOptions, Vector4MotionAdapter>))]
  9. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Quaternion, NoOptions, QuaternionMotionAdapter>))]
  10. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Color, NoOptions, ColorMotionAdapter>))]
  11. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Rect, NoOptions, RectMotionAdapter>))]
  12. namespace LitMotion.Adapters
  13. {
  14. public readonly struct Vector2MotionAdapter : IMotionAdapter<Vector2, NoOptions>
  15. {
  16. public Vector2 Evaluate(ref Vector2 startValue, ref Vector2 endValue, ref NoOptions options, in MotionEvaluationContext context)
  17. {
  18. return Vector2.LerpUnclamped(startValue, endValue, context.Progress);
  19. }
  20. }
  21. public readonly struct Vector3MotionAdapter : IMotionAdapter<Vector3, NoOptions>
  22. {
  23. public Vector3 Evaluate(ref Vector3 startValue, ref Vector3 endValue, ref NoOptions options, in MotionEvaluationContext context)
  24. {
  25. return Vector3.LerpUnclamped(startValue, endValue, context.Progress);
  26. }
  27. }
  28. public readonly struct Vector4MotionAdapter : IMotionAdapter<Vector4, NoOptions>
  29. {
  30. public Vector4 Evaluate(ref Vector4 startValue, ref Vector4 endValue, ref NoOptions options, in MotionEvaluationContext context)
  31. {
  32. return Vector4.LerpUnclamped(startValue, endValue, context.Progress);
  33. }
  34. }
  35. public readonly struct QuaternionMotionAdapter : IMotionAdapter<Quaternion, NoOptions>
  36. {
  37. public Quaternion Evaluate(ref Quaternion startValue, ref Quaternion endValue, ref NoOptions options, in MotionEvaluationContext context)
  38. {
  39. return Quaternion.LerpUnclamped(startValue, endValue, context.Progress);
  40. }
  41. }
  42. public readonly struct ColorMotionAdapter : IMotionAdapter<Color, NoOptions>
  43. {
  44. public Color Evaluate(ref Color startValue, ref Color endValue, ref NoOptions options, in MotionEvaluationContext context)
  45. {
  46. return Color.LerpUnclamped(startValue, endValue, context.Progress);
  47. }
  48. }
  49. public readonly struct RectMotionAdapter : IMotionAdapter<Rect, NoOptions>
  50. {
  51. public Rect Evaluate(ref Rect startValue, ref Rect endValue, ref NoOptions options, in MotionEvaluationContext context)
  52. {
  53. var x = math.lerp(startValue.x, endValue.x, context.Progress);
  54. var y = math.lerp(startValue.y, endValue.y, context.Progress);
  55. var width = math.lerp(startValue.width, endValue.width, context.Progress);
  56. var height = math.lerp(startValue.height, endValue.height, context.Progress);
  57. return new Rect(x, y, width, height);
  58. }
  59. }
  60. }