Created
October 29, 2019 04:48
-
-
Save baobao/42c627a8c5f27fcc89c29cc5f8f5bf93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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