using System.Collections.Generic; using System.Diagnostics; namespace Cryville.Common { public class Coroutine { readonly IEnumerator _enumerator; readonly Stopwatch _stopwatch = new(); public float Progress { get; private set; } public Coroutine(IEnumerator enumerator) { _enumerator = enumerator; } public bool TickOnce() { if (!_enumerator.MoveNext()) return false; Progress = _enumerator.Current; return true; } public bool Tick(double minTime) { _stopwatch.Restart(); while (_stopwatch.Elapsed.TotalSeconds < minTime) { if (!_enumerator.MoveNext()) return false; Progress = _enumerator.Current; } return true; } } }