AsyncStartTrigger.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. using UnityEngine;
  3. namespace Cysharp.Threading.Tasks.Triggers
  4. {
  5. public static partial class AsyncTriggerExtensions
  6. {
  7. public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject)
  8. {
  9. return GetOrAddComponent<AsyncStartTrigger>(gameObject);
  10. }
  11. public static AsyncStartTrigger GetAsyncStartTrigger(this Component component)
  12. {
  13. return component.gameObject.GetAsyncStartTrigger();
  14. }
  15. }
  16. [DisallowMultipleComponent]
  17. public sealed class AsyncStartTrigger : AsyncTriggerBase<AsyncUnit>
  18. {
  19. bool called;
  20. void Start()
  21. {
  22. called = true;
  23. RaiseEvent(AsyncUnit.Default);
  24. }
  25. public UniTask StartAsync()
  26. {
  27. if (called) return UniTask.CompletedTask;
  28. return ((IAsyncOneShotTrigger)new AsyncTriggerHandler<AsyncUnit>(this, true)).OneShotAsync();
  29. }
  30. }
  31. }