示例#1
0
 public void Start()
 {
     // デリゲートに非同期関数を登録できる
     _action += UniTask.Action(async() =>
     {
         var result = await ReadFileAsync("@data.txt");
         Debug.Log(result);
     });
 }
示例#2
0
        private async UniTaskVoid Start()
        {
            var token = this.GetCancellationTokenOnDestroy();

            await UniTaskAsyncEnumerable.EveryUpdate()
            .Select((_, x) => x)
            .Take(5)
            // ForEachAsyncは同期的に次のMoveNextAsync()を呼びだす
            .ForEachAsync(_ =>
            {
                // 完了を待機する必要がない非同期処理ならば
                // UniTask.Void が利用できる
                UniTask.Action(async() =>
                {
                    Debug.Log("before await:" + Time.frameCount);
                    await UniTask.DelayFrame(10, cancellationToken: token);
                    Debug.Log("after await:" + Time.frameCount);
                });
            }, token);

            Debug.Log("Done!");
        }