public static async UniTask OnInvokeAsync(this UnityEvent unityEvent, CancellationToken cancellationToken) { using (var handler = unityEvent.GetAsyncEventHandler(cancellationToken)) { await handler.OnInvokeAsync(); } }
public static async UniTask OnInvokeAsync(this UnityEvent unityEvent) { using (var handler = unityEvent.GetAsyncEventHandler()) { await handler.OnInvokeAsync(); } }
/// <summary> /// イベントが発火するまで待機する /// </summary> private async UniTaskVoid MoveAsync( UnityEvent unityEvent, CancellationToken token) { using (var asyncHandler = unityEvent.GetAsyncEventHandler(token)) { // イベントが発火するまで待つ await asyncHandler.OnInvokeAsync(); Debug.Log("Event received!"); } }
private void Start() { // CancellationToken取得 var token = this.GetCancellationTokenOnDestroy(); // ButtonクリックのUnityEvent UnityEvent clickEvent = _button.onClick; // AsyncUnityEventHandlerをキャッシュ _asyncUnityEventHandler = clickEvent.GetAsyncEventHandler(token); MoveAsync(token).Forget(); }