Last active
November 27, 2019 10:03
-
-
Save LiekeVanmulken/3ebdf4437c67dad20d6d2dd1d13cb6e7 to your computer and use it in GitHub Desktop.
Revisions
-
Wouter Vanmulken renamed this gist
Nov 27, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Wouter Vanmulken created this gist
Nov 27, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ using System; using System.Collections.Generic; using UnityEditor; /// <summary> /// Call actions on the MainThread from a different thread. /// </summary> [InitializeOnLoad] public class MainThreadDispatcher { private static readonly Queue<Action> _executionQueue = new Queue<Action>(); static MainThreadDispatcher() { EditorApplication.update += Update; } static void Update() { lock (_executionQueue) { while (_executionQueue.Count > 0) { _executionQueue.Dequeue().Invoke(); } } } public static void Enqueue(Action action) { lock (_executionQueue) { _executionQueue.Enqueue(action); } } }