private void Start() { ITimerExecutor timerExecutor = new ThreadTimerExecutor(); timerExecutor.Start(); IAsyncResult asyncResult1 = null; asyncResult1 = timerExecutor.FixedRateAtDuration(time => { print($"time={time} thread id ={Thread.CurrentThread.ManagedThreadId}"); if (time >= 5000) { asyncResult1.Cancel(); } }, () => print($"结束"), 1000, 500, 5000); timerExecutor = new CoroutineTimerExecutor(); timerExecutor.Start(); IAsyncResult asyncResult2 = null; asyncResult2 = timerExecutor.FixedRateAtDuration(time => { print($"time={time} thread id ={Thread.CurrentThread.ManagedThreadId}"); if (time >= 5000) { asyncResult2.Cancel(); } }, () => print($"结束"), 1000, 500, 5000); }
public static void TextTyperEffect(Text textComponent, string content, long delta, Action onComplete) { if (null != textComponent && !string.IsNullOrEmpty(content)) { textComponent.text = ""; int length = 1; ITimerExecutor timerExecutor = new CoroutineTimerExecutor(); IAsyncResult asyncResult = null; asyncResult = timerExecutor.FixedRateAtDuration(deltaTime => { var subContent = content.Substring(0, length); textComponent.text = subContent; length++; if (length > content.Length) { onComplete?.Invoke(); asyncResult.Cancel(); } }, period: delta); } }