Skip to content

Commit 22700c0

Browse files
committed
Added a flush to the EventManager
1 parent 5ed8987 commit 22700c0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Assets/UnityEvents/Scripts/EventManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ public static void SendEvent<T_Event>(EventEntity entity, T_Event ev, EventUpdat
141141
}
142142
}
143143

144+
/// <summary>
145+
/// Flushes all currently queued events NOW
146+
/// </summary>
147+
public static void FlushAll()
148+
{
149+
_fixedUpdateSystems.ProcessEvents();
150+
_updateSystems.ProcessEvents();
151+
_lateUpdateSystems.ProcessEvents();
152+
}
153+
144154
/// <summary>
145155
/// Reset all the event systems with all update types.
146156
/// </summary>

Assets/UnityEvents/Tests/TestEventManager.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,24 @@ public IEnumerator TestMultipleEntitiesStandardVsJob()
200200
Assert.IsTrue(value == 20);
201201
}
202202

203+
[UnityTest]
204+
public IEnumerator TestFlush()
205+
{
206+
EventEntity entity = EventEntity.CreateEntity();
207+
208+
int value = 0;
209+
Action<EvSimpleEvent> callback = x => { value += x.value; };
210+
211+
EventManager.Subscribe(entity, callback, EventUpdateType.Update);
212+
213+
EventManager.SendEvent(entity, new EvSimpleEvent(10), EventUpdateType.Update);
214+
215+
EventManager.FlushAll();
216+
Assert.IsTrue(value == 10);
217+
218+
yield return null;
219+
220+
Assert.IsTrue(value == 10);
221+
}
203222
}
204223
}

0 commit comments

Comments
 (0)