How to convert DoTween to UniTask and wait to complete all sequences.

Intro

I thought that I want to treat as UniTask and wait all of sequences when I use DoTween.

I write the way down on this article so I won’t forget.

Environments

name
version

Unity
2020.3.4f1

DOTween (HOTween v2)
1….


This content originally appeared on DEV Community and was authored by KENTO⚽️XR Engineer?

Intro

I thought that I want to treat as UniTask and wait all of sequences when I use DoTween.

I write the way down on this article so I won't forget.

Environments

name version
Unity 2020.3.4f1
DOTween (HOTween v2) 1.2.632
UniTask 2.2.5

Setting up

First we’ll import DoTween and UniTask to our unity project.

Next set UNITASK_DOTWEEN_SUPPORT on Scripting Define Symbols and select Apply.

Alt Text

But under my environment it wasn't applied to change settings for unknown reasons.

So I opened whatever assembly definition assets in the project, modified them once, and revert them.

In my case, it worked that way.

Sample Code

using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Sample of DoTween which treats as UniTask and wait to finish the task. 
/// </summary>
public class WaitDoTweenTaskSample : MonoBehaviour
{
    /// <summary>
    /// For task text
    /// </summary>
    [SerializeField] private Text[] _taskTexts;

    /// <summary>
    /// For completion text
    /// </summary>
    [SerializeField] private Text _completeTaskText;

    async void Start()
    {
        //Wait to complete task gave to argument.
        await UniTask.WhenAll(FadeTasks(this.GetCancellationTokenOnDestroy()));
        //When completed, fade in the text.
        _completeTaskText.DOFade(1.0f, 2.0f).Play();
    }

    /// <summary>
    /// Return task list that converted the fade sequences.
    /// </summary>
    /// <param name="ct">CancelToken </param>
    /// <returns>Task list</returns>
    private List<UniTask> FadeTasks(CancellationToken ct)
    {
        var taskList = new List<UniTask>();

        foreach (var taskText in _taskTexts)
        {
            var randomValue = Random.Range(1.0f, 5.0f); 
            taskList.Add(  taskText.DOFade(1.0f, randomValue).Play().ToUniTask(cancellationToken: ct));
        }

        return taskList;
    }
}

Demo

After all of fade sequences completed, a completion text starts fade in.

Alt Text

Other Resources

UniTaskでDoTweenを使う In 2020/11


This content originally appeared on DEV Community and was authored by KENTO⚽️XR Engineer?


Print Share Comment Cite Upload Translate Updates
APA

KENTO⚽️XR Engineer? | Sciencx (2021-09-26T06:18:58+00:00) How to convert DoTween to UniTask and wait to complete all sequences.. Retrieved from https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/

MLA
" » How to convert DoTween to UniTask and wait to complete all sequences.." KENTO⚽️XR Engineer? | Sciencx - Sunday September 26, 2021, https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/
HARVARD
KENTO⚽️XR Engineer? | Sciencx Sunday September 26, 2021 » How to convert DoTween to UniTask and wait to complete all sequences.., viewed ,<https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/>
VANCOUVER
KENTO⚽️XR Engineer? | Sciencx - » How to convert DoTween to UniTask and wait to complete all sequences.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/
CHICAGO
" » How to convert DoTween to UniTask and wait to complete all sequences.." KENTO⚽️XR Engineer? | Sciencx - Accessed . https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/
IEEE
" » How to convert DoTween to UniTask and wait to complete all sequences.." KENTO⚽️XR Engineer? | Sciencx [Online]. Available: https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/. [Accessed: ]
rf:citation
» How to convert DoTween to UniTask and wait to complete all sequences. | KENTO⚽️XR Engineer? | Sciencx | https://www.scien.cx/2021/09/26/how-to-convert-dotween-to-unitask-and-wait-to-complete-all-sequences/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.