forked from zxl/LaboratoryProtection
79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using DragonSoul.Shared;
|
|
using TMPro;
|
|
|
|
namespace UnityTest.ZXL
|
|
{
|
|
public static class ETTaskHelper
|
|
{
|
|
public static async ETTask WaitFinish(Action action, ETCancellationToken token = null)
|
|
{
|
|
ETTask task = ETTask.Create();
|
|
await task;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 等待完成(自动床奶奶)
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
public static async ETTask<bool> WaitCompletion(ETCancellationToken token = null)
|
|
{
|
|
ETTask<bool> task = ETTask<bool>.Create();
|
|
|
|
token?.Add(Cancel);
|
|
|
|
void Cancel()
|
|
{
|
|
task.SetResult(false);
|
|
token = new ETCancellationToken();
|
|
}
|
|
|
|
var isTrue = await task;
|
|
token.Remove(Cancel);
|
|
|
|
return isTrue;
|
|
}
|
|
|
|
public static async ETTask<bool> WaitCompletion(ETTask<bool> task, ETCancellationToken token = null)
|
|
{
|
|
task = ETTask<bool>.Create();
|
|
|
|
token?.Add(Cancel);
|
|
|
|
void Cancel()
|
|
{
|
|
task.SetResult(false);
|
|
token = new ETCancellationToken();
|
|
}
|
|
|
|
var isTrue = await task;
|
|
token?.Remove(Cancel);
|
|
|
|
return isTrue;
|
|
}
|
|
|
|
public static async ETTask WaitTime(float time, ETCancellationToken token = null)
|
|
{
|
|
await UniTask.Delay(TimeSpan.FromSeconds(time));
|
|
}
|
|
|
|
public static async ETTask WaitDoTMPText(this TextMeshProUGUI text, string content, string audioName, ETCancellationToken token = null)
|
|
{
|
|
bool isEnd = false;
|
|
|
|
var t = 0.1f * content.Length;
|
|
DOTween.KillAll();
|
|
|
|
if (audioName != "")
|
|
{
|
|
t = Script.AudioManager.Instance.PlayOtherSound(false, $"6-4/{audioName}") + 0.1f;
|
|
}
|
|
|
|
await DOTween.To(() => string.Empty, value => text.text = value, content, t)
|
|
.SetEase(Ease.Linear).AwaitForComplete().SuppressCancellationThrow();
|
|
}
|
|
}
|
|
} |