예제 #1
0
 public static async UniTask OnInvokeAsync(this UnityEvent unityEvent, CancellationToken cancellationToken)
 {
     using (var handler = unityEvent.GetAsyncEventHandler(cancellationToken))
     {
         await handler.OnInvokeAsync();
     }
 }
예제 #2
0
 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();
        }