Skip to content

Instantly share code, notes, and snippets.

@baobao
Created October 29, 2019 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/42c627a8c5f27fcc89c29cc5f8f5bf93 to your computer and use it in GitHub Desktop.
Save baobao/42c627a8c5f27fcc89c29cc5f8f5bf93 to your computer and use it in GitHub Desktop.
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