Coroutine/Coroutine/ActiveCoroutine.cs

37 lines
1.1 KiB
C#
Raw Normal View History

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