mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-12-14 13:59:23 +01:00
37 lines
No EOL
1.1 KiB
C#
37 lines
No EOL
1.1 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Coroutine {
|
|
public class ActiveCoroutine {
|
|
|
|
private readonly IEnumerator<IWait> enumerator;
|
|
public bool IsFinished { get; private set; }
|
|
|
|
internal ActiveCoroutine(IEnumerator<IWait> enumerator) {
|
|
this.enumerator = enumerator;
|
|
this.enumerator.MoveNext();
|
|
}
|
|
|
|
internal bool Tick(double deltaSeconds) {
|
|
var curr = this.enumerator.Current;
|
|
if (curr != null && curr.Tick(deltaSeconds)) {
|
|
if (!this.enumerator.MoveNext())
|
|
this.IsFinished = true;
|
|
}
|
|
return this.IsFinished;
|
|
}
|
|
|
|
internal bool OnEvent(Event evt) {
|
|
var curr = this.enumerator.Current;
|
|
if (curr != null && curr.OnEvent(evt)) {
|
|
if (!this.enumerator.MoveNext())
|
|
this.IsFinished = true;
|
|
}
|
|
return this.IsFinished;
|
|
}
|
|
|
|
internal WaitType GetCurrentType() {
|
|
return this.enumerator.Current.GetWaitType();
|
|
}
|
|
|
|
}
|
|
} |