/// <summary>
    /// ボタンが押されるのを待つ
    /// </summary>
    /// <returns></returns>
    private async void AwaitButton(CancellationToken token)
    {
        IAsyncClickEventHandler handler = _button.GetAsyncClickEventHandler(token);
        await handler.OnClickAsync();

        Debug.Log("onClickButton");
    }
    private async UniTask ページ送りAsync(StoryContent[] story)
    {
        var content  = story.First();
        var contents = story.ToDictionary(x => x.Id);

        while (true)
        {
            _text.text = content.Text;
            Texture2D image = null;
            try
            {
                image = await content.ImageTask();
            }
            catch (ResourceLoadException ex)
            {
                // 画像読み込み時の例外処理
                // 今回はログを出しつつ処理を継続させる
                Debug.LogWarning(ex);
            }
            _image.texture = image;

            var nextContentId = 0;
            if (content.SelectionContents.Any())
            {
                using (var cts = new CancellationTokenSource())
                {
                    var 選択肢待ち = content.SelectionContents.Await選択肢(_選択肢Prefab, _選択肢Container, cts.Token, _選択肢プール);
                    nextContentId = await 選択肢待ち;
                    cts.Cancel();
                }

                Release選択肢();
            }
            else
            {
                await _clickHandler.OnClickAsync();

                nextContentId = content.Id + 1;
            }

            if (!contents.TryGetValue(nextContentId, out content))
            {
                break;
            }
        }

        _text.text = "おわり";
    }
    private async UniTask ページ送りAsync(StoryContent[] story)
    {
        var content  = story.First();
        var contents = story.ToDictionary(x => x.Id);

        while (true)
        {
            _text.text     = content.Text;
            _image.texture = content.Image;

            var nextContentId = 0;
            if (content.SelectionContents.Any())
            {
                using (var cts = new CancellationTokenSource())
                {
                    var 選択肢待ち = content.SelectionContents.Await選択肢(_選択肢Prefab, _選択肢Container, cts.Token, _選択肢プール);
                    nextContentId = await 選択肢待ち;
                    cts.Cancel();
                }

                Release選択肢();
            }
            else
            {
                await _clickHandler.OnClickAsync();

                nextContentId = content.Id + 1;
            }

            if (!contents.TryGetValue(nextContentId, out content))
            {
                break;
            }
        }

        _text.text = "おわり";
    }
Esempio n. 4
0
    static async UniTask OnClick(Button button, IAsyncClickEventHandler onclickHandler)
    {
        await onclickHandler.OnClickAsync();

        button.interactable = false;
    }