mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-11-26 06:58:35 +01:00
Compare commits
4 commits
fe9e5c658a
...
7501ffaf9c
Author | SHA1 | Date | |
---|---|---|---|
7501ffaf9c | |||
aa8a2b8ff9 | |||
dc5206fced | |||
201369f167 |
7 changed files with 44 additions and 24 deletions
|
@ -84,7 +84,7 @@ namespace Coroutine {
|
|||
}
|
||||
|
||||
internal bool OnEvent(Event evt) {
|
||||
if (!this.WasCanceled && Equals(this.current.Event, evt))
|
||||
if (!this.WasCanceled && object.Equals(this.current.Event, evt))
|
||||
this.MoveNext();
|
||||
return this.IsFinished;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<PropertyGroup>
|
||||
<TargetFrameworks>net45;netstandard2.0;net6.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -13,7 +14,7 @@
|
|||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageIcon>Logo.png</PackageIcon>
|
||||
<VersionPrefix>2.1.4</VersionPrefix>
|
||||
<VersionPrefix>2.1.5</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -11,42 +11,48 @@ namespace Coroutine {
|
|||
private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance();
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/>
|
||||
public static int TickingCount => Instance.TickingCount;
|
||||
public static int TickingCount => CoroutineHandler.Instance.TickingCount;
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.EventCount"/>
|
||||
public static int EventCount => Instance.EventCount;
|
||||
public static int EventCount => CoroutineHandler.Instance.EventCount;
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerable{Wait},string,int)"/>
|
||||
public static ActiveCoroutine Start(IEnumerable<Wait> coroutine, string name = "", int priority = 0) {
|
||||
return Instance.Start(coroutine, name, priority);
|
||||
return CoroutineHandler.Instance.Start(coroutine, name, priority);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerator{Wait},string,int)"/>
|
||||
public static ActiveCoroutine Start(IEnumerator<Wait> coroutine, string name = "", int priority = 0) {
|
||||
return Instance.Start(coroutine, name, priority);
|
||||
return CoroutineHandler.Instance.Start(coroutine, name, priority);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater"/>
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater(Wait,Action,string,int)"/>
|
||||
public static ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
||||
return Instance.InvokeLater(wait, action, name, priority);
|
||||
return CoroutineHandler.Instance.InvokeLater(wait, action, name, priority);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater(Event,Action,string,int)"/>
|
||||
public static ActiveCoroutine InvokeLater(Event evt, Action action, string name = "", int priority = 0) {
|
||||
return CoroutineHandler.Instance.InvokeLater(evt, action, name, priority);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(double)"/>
|
||||
public static void Tick(double deltaSeconds) {
|
||||
Instance.Tick(deltaSeconds);
|
||||
CoroutineHandler.Instance.Tick(deltaSeconds);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/>
|
||||
public static void Tick(TimeSpan delta) {
|
||||
Instance.Tick(delta);
|
||||
CoroutineHandler.Instance.Tick(delta);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/>
|
||||
public static void RaiseEvent(Event evt) {
|
||||
Instance.RaiseEvent(evt);
|
||||
CoroutineHandler.Instance.RaiseEvent(evt);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/>
|
||||
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
|
||||
return Instance.GetActiveCoroutines();
|
||||
return CoroutineHandler.Instance.GetActiveCoroutines();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,20 @@ namespace Coroutine {
|
|||
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
|
||||
/// <returns>An active coroutine object representing this coroutine</returns>
|
||||
public ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
||||
return this.Start(InvokeLaterImpl(wait, action), name, priority);
|
||||
return this.Start(CoroutineHandlerInstance.InvokeLaterImpl(wait, action), name, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Causes the given action to be invoked after the given <see cref="Event"/>.
|
||||
/// This is equivalent to a coroutine that waits for the given wait and then executes the given <see cref="Action"/>.
|
||||
/// </summary>
|
||||
/// <param name="evt">The event to wait for</param>
|
||||
/// <param name="action">The action to execute after waiting</param>
|
||||
/// <param name="name">The <see cref="ActiveCoroutine.Name"/> that the underlying coroutine should have. Defaults to an empty string.</param>
|
||||
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
|
||||
/// <returns>An active coroutine object representing this coroutine</returns>
|
||||
public ActiveCoroutine InvokeLater(Event evt, Action action, string name = "", int priority = 0) {
|
||||
return this.InvokeLater(new Wait(evt), action, name, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -9,19 +9,19 @@ namespace Example {
|
|||
private static readonly Event TestEvent = new Event();
|
||||
|
||||
public static void Main() {
|
||||
var seconds = CoroutineHandler.Start(WaitSeconds(), "Awesome Waiting Coroutine");
|
||||
CoroutineHandler.Start(PrintEvery10Seconds(seconds));
|
||||
var seconds = CoroutineHandler.Start(Example.WaitSeconds(), "Awesome Waiting Coroutine");
|
||||
CoroutineHandler.Start(Example.PrintEvery10Seconds(seconds));
|
||||
|
||||
CoroutineHandler.Start(EmptyCoroutine());
|
||||
CoroutineHandler.Start(Example.EmptyCoroutine());
|
||||
|
||||
CoroutineHandler.InvokeLater(new Wait(5), () => {
|
||||
Console.WriteLine("Raising test event");
|
||||
CoroutineHandler.RaiseEvent(TestEvent);
|
||||
CoroutineHandler.RaiseEvent(Example.TestEvent);
|
||||
});
|
||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("Example event received"));
|
||||
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("Example event received"));
|
||||
|
||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
|
||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
|
||||
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
|
||||
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
|
||||
|
||||
var lastTime = DateTime.Now;
|
||||
while (true) {
|
||||
|
@ -38,7 +38,7 @@ namespace Example {
|
|||
Console.WriteLine("After 1 second " + DateTime.Now);
|
||||
yield return new Wait(9);
|
||||
Console.WriteLine("After 10 seconds " + DateTime.Now);
|
||||
CoroutineHandler.Start(NestedCoroutine());
|
||||
CoroutineHandler.Start(Example.NestedCoroutine());
|
||||
yield return new Wait(5);
|
||||
Console.WriteLine("After 5 more seconds " + DateTime.Now);
|
||||
yield return new Wait(10);
|
||||
|
|
|
@ -128,7 +128,7 @@ namespace Tests {
|
|||
var p = CoroutineHandler.Start(Parent());
|
||||
CoroutineHandler.RaiseEvent(onParentCreated);
|
||||
// Nested corotuine starting in OnFinished.
|
||||
p.OnFinished += ac => {
|
||||
p.OnFinished += _ => {
|
||||
CoroutineHandler.Start(Child());
|
||||
CoroutineHandler.RaiseEvent(onChildCreated);
|
||||
};
|
||||
|
|
|
@ -164,7 +164,7 @@ namespace Tests {
|
|||
// Nested corotuine starting.
|
||||
var p = CoroutineHandler.Start(Parent());
|
||||
// Nested corotuine starting in OnFinished.
|
||||
p.OnFinished += ac => CoroutineHandler.Start(Child());
|
||||
p.OnFinished += _ => CoroutineHandler.Start(Child());
|
||||
}
|
||||
|
||||
var always = CoroutineHandler.Start(AlwaysRunning());
|
||||
|
@ -408,7 +408,7 @@ namespace Tests {
|
|||
var p = CoroutineHandler.Start(Parent());
|
||||
CoroutineHandler.RaiseEvent(onParentCreated);
|
||||
// Nested corotuine starting in OnFinished.
|
||||
p.OnFinished += ac => {
|
||||
p.OnFinished += _ => {
|
||||
CoroutineHandler.Start(Child());
|
||||
CoroutineHandler.RaiseEvent(onChildCreated);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue