MotionAwaiter.cs 953 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace LitMotion
  4. {
  5. public readonly struct MotionAwaiter : ICriticalNotifyCompletion
  6. {
  7. readonly MotionHandle handle;
  8. public bool IsCompleted => !handle.IsActive();
  9. public MotionAwaiter(MotionHandle handle)
  10. {
  11. this.handle = handle;
  12. }
  13. public MotionAwaiter GetAwaiter()
  14. {
  15. return this;
  16. }
  17. public void GetResult()
  18. {
  19. }
  20. public void OnCompleted(Action continuation)
  21. {
  22. UnsafeOnCompleted(continuation);
  23. }
  24. public void UnsafeOnCompleted(Action continuation)
  25. {
  26. if (continuation == null) return;
  27. ref var callbackData = ref MotionStorageManager.GetMotionCallbackDataRef(handle);
  28. callbackData.OnCompleteAction += continuation;
  29. callbackData.OnCancelAction += continuation;
  30. }
  31. }
  32. }