using System; namespace Coroutine { /// /// Represents either an amount of time, or an that is being waited for by an . /// public struct Wait { private readonly Event evt; private double seconds; /// /// Creates a new wait that waits for the given . /// /// The event to wait for public Wait(Event evt) { this.evt = evt; this.seconds = 0; } /// /// Creates a new wait that waits for the given amount of seconds. /// /// The amount of seconds to wait for public Wait(double seconds) { this.seconds = seconds; this.evt = null; } /// /// Creates a new wait that waits for the given . /// Note that the exact value may be slightly different, since waits operate in rather than ticks. /// /// The time span to wait for public Wait(TimeSpan time) : this(time.TotalSeconds) { } internal bool Tick(double deltaSeconds) { this.seconds -= deltaSeconds; return this.seconds <= 0; } internal bool OnEvent(Event evt) { return Equals(evt, this.evt); } internal bool IsWaitingForEvent() { return this.evt != null; } } }