public static void RunOnMainThread(Action action) { UnityDispatchQueue instance = GetInstance(); lock (instance.actionsQueue) { instance.actionsQueue.Enqueue(action); } }
private static UnityDispatchQueue GetInstance() { if (!_instance) { _instance = FindObjectOfType <UnityDispatchQueue>(); } if (!_instance) { GameObject go = new GameObject(nameof(UnityDispatchQueue)); _instance = go.AddComponent <UnityDispatchQueue>(); DontDestroyOnLoad(_instance); } return(_instance); }
private void OnDestroy() { _instance = null; }