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
.
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.
Other Resources
This content originally appeared on DEV Community and was authored by KENTO⚽️XR Engineer?
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.