FixedStringMotionAdapters.cs 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Unity.Collections;
  2. using Unity.Jobs;
  3. using LitMotion;
  4. using LitMotion.Adapters;
  5. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<FixedString32Bytes, StringOptions, FixedString32BytesMotionAdapter>))]
  6. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<FixedString64Bytes, StringOptions, FixedString64BytesMotionAdapter>))]
  7. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<FixedString128Bytes, StringOptions, FixedString128BytesMotionAdapter>))]
  8. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<FixedString512Bytes, StringOptions, FixedString512BytesMotionAdapter>))]
  9. [assembly: RegisterGenericJobType(typeof(MotionUpdateJob<FixedString4096Bytes, StringOptions, FixedString4096BytesMotionAdapter>))]
  10. namespace LitMotion.Adapters
  11. {
  12. public readonly struct FixedString32BytesMotionAdapter : IMotionAdapter<FixedString32Bytes, StringOptions>
  13. {
  14. public FixedString32Bytes Evaluate(ref FixedString32Bytes startValue, ref FixedString32Bytes endValue, ref StringOptions options, in MotionEvaluationContext context)
  15. {
  16. var start = startValue;
  17. var end = endValue;
  18. var customScrambleChars = options.CustomScrambleChars;
  19. ref var randomState = ref options.RandomState;
  20. if (randomState.state == 0) randomState = ref SharedRandom.Random;
  21. FixedStringHelper.Interpolate(ref start, ref end, context.Progress, options.ScrambleMode, options.RichTextEnabled, ref randomState, ref customScrambleChars, out var result);
  22. return result;
  23. }
  24. }
  25. public readonly struct FixedString64BytesMotionAdapter : IMotionAdapter<FixedString64Bytes, StringOptions>
  26. {
  27. public FixedString64Bytes Evaluate(ref FixedString64Bytes startValue, ref FixedString64Bytes endValue, ref StringOptions options, in MotionEvaluationContext context)
  28. {
  29. var start = startValue;
  30. var end = endValue;
  31. var customScrambleChars = options.CustomScrambleChars;
  32. ref var randomState = ref options.RandomState;
  33. if (randomState.state == 0) randomState = ref SharedRandom.Random;
  34. FixedStringHelper.Interpolate(ref start, ref end, context.Progress, options.ScrambleMode, options.RichTextEnabled, ref randomState, ref customScrambleChars, out var result);
  35. return result;
  36. }
  37. }
  38. public readonly struct FixedString128BytesMotionAdapter : IMotionAdapter<FixedString128Bytes, StringOptions>
  39. {
  40. public FixedString128Bytes Evaluate(ref FixedString128Bytes startValue, ref FixedString128Bytes endValue, ref StringOptions options, in MotionEvaluationContext context)
  41. {
  42. var start = startValue;
  43. var end = endValue;
  44. var customScrambleChars = options.CustomScrambleChars;
  45. ref var randomState = ref options.RandomState;
  46. if (randomState.state == 0) randomState = ref SharedRandom.Random;
  47. FixedStringHelper.Interpolate(ref start, ref end, context.Progress, options.ScrambleMode, options.RichTextEnabled, ref randomState, ref customScrambleChars, out var result);
  48. return result;
  49. }
  50. }
  51. public readonly struct FixedString512BytesMotionAdapter : IMotionAdapter<FixedString512Bytes, StringOptions>
  52. {
  53. public FixedString512Bytes Evaluate(ref FixedString512Bytes startValue, ref FixedString512Bytes endValue, ref StringOptions options, in MotionEvaluationContext context)
  54. {
  55. var start = startValue;
  56. var end = endValue;
  57. var customScrambleChars = options.CustomScrambleChars;
  58. ref var randomState = ref options.RandomState;
  59. if (randomState.state == 0) randomState = ref SharedRandom.Random;
  60. FixedStringHelper.Interpolate(ref start, ref end, context.Progress, options.ScrambleMode, options.RichTextEnabled, ref randomState, ref customScrambleChars, out var result);
  61. return result;
  62. }
  63. }
  64. public readonly struct FixedString4096BytesMotionAdapter : IMotionAdapter<FixedString4096Bytes, StringOptions>
  65. {
  66. public FixedString4096Bytes Evaluate(ref FixedString4096Bytes startValue, ref FixedString4096Bytes endValue, ref StringOptions options, in MotionEvaluationContext context)
  67. {
  68. var start = startValue;
  69. var end = endValue;
  70. var customScrambleChars = options.CustomScrambleChars;
  71. ref var randomState = ref options.RandomState;
  72. if (randomState.state == 0) randomState = ref SharedRandom.Random;
  73. FixedStringHelper.Interpolate(ref start, ref end, context.Progress, options.ScrambleMode, options.RichTextEnabled, ref randomState, ref customScrambleChars, out var result);
  74. return result;
  75. }
  76. }
  77. }