2019-06-22 17:24:50 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Coroutine {
|
2019-11-20 11:30:28 +01:00
|
|
|
internal struct Coroutine {
|
2019-06-22 17:24:50 +02:00
|
|
|
|
2019-11-20 11:30:28 +01:00
|
|
|
private readonly IEnumerator<IWait> enumerator;
|
2019-06-22 17:24:50 +02:00
|
|
|
|
2019-11-20 11:30:28 +01:00
|
|
|
public Coroutine(IEnumerator<IWait> enumerator) {
|
2019-06-22 17:24:50 +02:00
|
|
|
this.enumerator = enumerator;
|
|
|
|
this.enumerator.MoveNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Tick(double deltaSeconds) {
|
|
|
|
var curr = this.enumerator.Current;
|
|
|
|
if (curr != null && curr.Tick(deltaSeconds)) {
|
|
|
|
if (!this.enumerator.MoveNext())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OnEvent(Event evt) {
|
|
|
|
var curr = this.enumerator.Current;
|
|
|
|
if (curr != null && curr.OnEvent(evt)) {
|
|
|
|
if (!this.enumerator.MoveNext())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public WaitType GetCurrentType() {
|
|
|
|
return this.enumerator.Current.GetWaitType();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|