forked from zxl/LaboratoryProtection
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Cysharp.Threading.Tasks;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PMaker.Extension
|
|
{
|
|
public static class UniTaskUGUIExtension
|
|
{
|
|
/// <summary>
|
|
/// 异步匀速率打字机
|
|
/// </summary>
|
|
/// <param name="text">UGUI.Text组件</param>
|
|
/// <param name="data">待打文字</param>
|
|
/// <param name="millisecondsDelay">打字间隔(每字符)单位为毫秒(milliseconds)</param>
|
|
/// <returns></returns>
|
|
public static async UniTask DoTextAsync(this Text text, string data, int millisecondsDelay)
|
|
{
|
|
text.text = string.Empty;
|
|
foreach (var item in data)
|
|
{
|
|
text.text += item;
|
|
await UniTask.Delay(millisecondsDelay);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步匀速率打字机, 无返回值 (UniTask官方文档指出, UniTaskVoid.Forget()比UniTask.Forget()更加高效.)
|
|
/// </summary>
|
|
/// <param name="text">UGUI.Text组件</param>
|
|
/// <param name="data">待打文字</param>
|
|
/// <param name="millisecondsDelay">打字间隔(每字符)单位为毫秒(milliseconds)</param>
|
|
/// <returns></returns>
|
|
public static async UniTaskVoid DoTextAsyncVoid(this Text text, string data, int millisecondsDelay)
|
|
{
|
|
await text.DoTextAsync(data, millisecondsDelay);
|
|
}
|
|
}
|
|
|
|
public static class UniTaskMonoBehaviourExtension
|
|
{
|
|
public static void Async(this MonoBehaviour behaviour, Func<UniTaskVoid> func)
|
|
{
|
|
UniTask.Void(func);
|
|
}
|
|
}
|
|
}
|
|
|