Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Threading;
using System.Threading.Tasks;
using DG.Tweening;
using UnityEngine;
// DOTweenAwaiterExtensionサンプルコード(キャンセル有り)
public class DOTweenAwaiterExtensionWithCancel : MonoBehaviour
{
async void Start()
{
var cts = new CancellationTokenSource();
CancelTween();
async Task CancelTween()
{
// 1秒後にキャンセル
await Task.Delay(1000);
cts.Cancel();
cts.Dispose();
cts = null;
}
try
{
// キャンセルトークンをTweenに渡す
await transform.DOLocalMoveX(3f, 2f).ToAwaiter(cts.Token);
}
catch (OperationCanceledException e)
{
// キャンセルした
}
await transform.DOLocalMoveY(3f, 2f).ToAwaiter();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment