AsyncAwakeTrigger.cs 942 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. using System.Threading;
  3. using UnityEngine;
  4. namespace Cysharp.Threading.Tasks.Triggers
  5. {
  6. public static partial class AsyncTriggerExtensions
  7. {
  8. public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject)
  9. {
  10. return GetOrAddComponent<AsyncAwakeTrigger>(gameObject);
  11. }
  12. public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component)
  13. {
  14. return component.gameObject.GetAsyncAwakeTrigger();
  15. }
  16. }
  17. [DisallowMultipleComponent]
  18. public sealed class AsyncAwakeTrigger : AsyncTriggerBase<AsyncUnit>
  19. {
  20. public UniTask AwakeAsync()
  21. {
  22. if (calledAwake) return UniTask.CompletedTask;
  23. return ((IAsyncOneShotTrigger)new AsyncTriggerHandler<AsyncUnit>(this, true)).OneShotAsync();
  24. }
  25. }
  26. }