Initial commit
This commit is contained in:
20
Assets/Scripting/Robot/UnityMainThreadDispatcher.cs
Normal file
20
Assets/Scripting/Robot/UnityMainThreadDispatcher.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
public static class UnityMainThreadDispatcher
|
||||
{
|
||||
private static readonly ConcurrentQueue<Action> _executionQueue = new();
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
while (_executionQueue.TryDequeue(out var action))
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Enqueue(Action action)
|
||||
{
|
||||
_executionQueue.Enqueue(action);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user