MotionCallbackData.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using Unity.Collections.LowLevel.Unsafe;
  4. namespace LitMotion
  5. {
  6. /// <summary>
  7. /// A structure that holds motion callbacks.
  8. /// </summary>
  9. public struct MotionCallbackData
  10. {
  11. public byte StateCount;
  12. public bool IsCallbackRunning;
  13. public bool CancelOnError;
  14. public bool SkipValuesDuringDelay;
  15. public object State1;
  16. public object State2;
  17. public object State3;
  18. public object UpdateAction;
  19. public Action OnCompleteAction;
  20. public Action OnCancelAction;
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. public void InvokeUnsafe<TValue>(in TValue value) where TValue : unmanaged
  23. {
  24. switch (StateCount)
  25. {
  26. case 0:
  27. UnsafeUtility.As<object, Action<TValue>>(ref UpdateAction)?.Invoke(value);
  28. break;
  29. case 1:
  30. UnsafeUtility.As<object, Action<TValue, object>>(ref UpdateAction)?.Invoke(value, State1);
  31. break;
  32. case 2:
  33. UnsafeUtility.As<object, Action<TValue, object, object>>(ref UpdateAction)?.Invoke(value, State1, State2);
  34. break;
  35. case 3:
  36. UnsafeUtility.As<object, Action<TValue, object, object, object>>(ref UpdateAction)?.Invoke(value, State1, State2, State3);
  37. break;
  38. }
  39. }
  40. public readonly static MotionCallbackData Default = new()
  41. {
  42. SkipValuesDuringDelay = true,
  43. };
  44. }
  45. }