PunchMotionAdapters.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Unity.Jobs;
  2. using UnityEngine;
  3. using LitMotion;
  4. using LitMotion.Adapters;
  5. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<float, PunchOptions, FloatPunchMotionAdapter>))]
  6. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Vector2, PunchOptions, Vector2PunchMotionAdapter>))]
  7. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<Vector3, PunchOptions, Vector3PunchMotionAdapter>))]
  8. namespace LitMotion.Adapters
  9. {
  10. // Note: Punch motion uses startValue as offset and endValue as vibration strength.
  11. public readonly struct FloatPunchMotionAdapter : IMotionAdapter<float, PunchOptions>
  12. {
  13. public float Evaluate(ref float startValue, ref float endValue, ref PunchOptions options, in MotionEvaluationContext context)
  14. {
  15. VibrationHelper.EvaluateStrength(endValue, options.Frequency, options.DampingRatio, context.Progress, out var result);
  16. return startValue + result;
  17. }
  18. }
  19. public readonly struct Vector2PunchMotionAdapter : IMotionAdapter<Vector2, PunchOptions>
  20. {
  21. public Vector2 Evaluate(ref Vector2 startValue, ref Vector2 endValue, ref PunchOptions options, in MotionEvaluationContext context)
  22. {
  23. VibrationHelper.EvaluateStrength(endValue, options.Frequency, options.DampingRatio, context.Progress, out var result);
  24. return startValue + result;
  25. }
  26. }
  27. public readonly struct Vector3PunchMotionAdapter : IMotionAdapter<Vector3, PunchOptions>
  28. {
  29. public Vector3 Evaluate(ref Vector3 startValue, ref Vector3 endValue, ref PunchOptions options, in MotionEvaluationContext context)
  30. {
  31. VibrationHelper.EvaluateStrength(endValue, options.Frequency, options.DampingRatio, context.Progress, out var result);
  32. return startValue + result;
  33. }
  34. }
  35. }