forked from zxl/LaboratoryProtection
25 lines
713 B
C#
25 lines
713 B
C#
using Cysharp.Threading.Tasks;
|
|
|
|
using System;
|
|
using System.Threading;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
public static class TimelineExtension
|
|
{
|
|
public static async UniTask WaitPlayAsync(this PlayableDirector director, CancellationToken cancellationToken)
|
|
{
|
|
var duration = director.duration;
|
|
director.Play();
|
|
var speed = director.playableGraph.GetRootPlayable(0).GetSpeed();
|
|
Debug.Log(speed);
|
|
var time = duration / speed;
|
|
var isCancel = await UniTask.Delay(TimeSpan.FromSeconds(time), cancellationToken: cancellationToken).SuppressCancellationThrow();
|
|
if (isCancel == true)
|
|
{
|
|
director.Stop();
|
|
}
|
|
}
|
|
}
|