course_heia_techimm_haptics.../Assets/Plugins/CodeAssist/Editor/MainThreadDispatcher.cs

35 lines
748 B
C#
Raw Normal View History

2025-07-12 18:59:18 +02:00
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using UnityEngine;
using UnityEditor;
#nullable enable
namespace Meryel.UnityCodeAssist.Editor
{
[InitializeOnLoad]
public static class MainThreadDispatcher
{
readonly static ConcurrentBag<System.Action> actions;
static MainThreadDispatcher()
{
actions = new ConcurrentBag<System.Action>();
EditorApplication.update += Update;
}
static void Update()
{
while (actions.TryTake(out var action))
{
action.Invoke();
}
}
public static void Add(System.Action action) => actions.Add(action);
}
}