20 lines
435 B
C#
20 lines
435 B
C#
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);
|
|
}
|
|
} |