mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
41 lines
768 B
C#
41 lines
768 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Il2CppInterop.Runtime.Attributes;
|
|
using Reactor.Utilities.Attributes;
|
|
using UnityEngine;
|
|
|
|
namespace Reactor.Utilities;
|
|
|
|
[RegisterInIl2Cpp]
|
|
public sealed class Dispatcher : MonoBehaviour
|
|
{
|
|
public static Dispatcher Instance { get; private set; } = null!;
|
|
|
|
private readonly Queue<Action> _queue = new();
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
lock (_queue)
|
|
{
|
|
while (_queue.Count > 0)
|
|
{
|
|
_queue.Dequeue().Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
[HideFromIl2Cpp]
|
|
public void Enqueue(Action action)
|
|
{
|
|
lock (_queue)
|
|
{
|
|
_queue.Enqueue(action);
|
|
}
|
|
}
|
|
}
|