Skip to content

Commit ec29437

Browse files
authored
Added overloaded Enqueue(Action action)
This little convenience make the simplest usage a one liner: `UnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log ("This is executed from the main thread"));` I've implemented this in my own project and it seems to be working just fine. I'm no Unity expert, so if there are any risks to this I may not be able to tell.
1 parent ae76667 commit ec29437

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

UnityMainThreadDispatcher.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public void Enqueue(IEnumerator action) {
4646
});
4747
}
4848
}
49+
50+
/// <summary>
51+
/// Locks the queue and adds the Action to the queue
52+
/// </summary>
53+
/// <param name="action">function that will be executed from the main thread.</param>
54+
public void Enqueue(Action action)
55+
{
56+
Enqueue(ActionWrapper(action));
57+
}
58+
IEnumerator ActionWrapper(Action a)
59+
{
60+
a();
61+
yield return null;
62+
}
4963

5064

5165
private static UnityMainThreadDispatcher _instance = null;

0 commit comments

Comments
 (0)