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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Coroutine.cs.meta
Normal file
11
Assets/Cryville/Common/Coroutine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 387adc7d494be0147b7cb930bc2e726b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,11 @@ namespace Cryville.Crtr {
|
||||
/// <summary>
|
||||
/// The index of the event to be handled next.
|
||||
/// </summary>
|
||||
protected int EventId;
|
||||
public int EventId { get; protected set; }
|
||||
/// <summary>
|
||||
/// The event count.
|
||||
/// </summary>
|
||||
public int EventCount { get { return Events.Count; } }
|
||||
/// <summary>
|
||||
/// The event list.
|
||||
/// </summary>
|
||||
@@ -66,6 +70,13 @@ namespace Cryville.Crtr {
|
||||
ForwardToTime(double.PositiveInfinity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forwards to the next event.
|
||||
/// </summary>
|
||||
public void ForwardOnce() {
|
||||
ForwardOnceToTime(double.PositiveInfinity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forwards the time by the specified span and walks through all the encountered events.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user