Add progress tracking for chart loading.
This commit is contained in:
26
Assets/Cryville/Common/Coroutine.cs
Normal file
26
Assets/Cryville/Common/Coroutine.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common {
|
||||
public class Coroutine {
|
||||
readonly IEnumerator<float> _enumerator;
|
||||
readonly Stopwatch _stopwatch = new Stopwatch();
|
||||
public float Progress { get; private set; }
|
||||
public Coroutine(IEnumerator<float> 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user