public static void DemoEditorCoroutines()
 {
     // adds a menu item to test the coroutine system.
     if (!Application.isPlaying)
     {
         // lets fire off the demo coroutine with a UI so we can see what its doing. We could also run it without a UI by using EditorCoroutineRunner.StartCoroutine(...)
         EditorCoroutineRunner.StartCoroutineWithUI(DemoCoroutiune(), "Lotte's Coroutine Demo", true);
     }
 }
        /// <summary>
        /// Send a Coroutine to be run on the main thread. See EditorDispatchActions for some common usecases.
        /// </summary>
        /// <param name="task">A coroutine to run on the main thread</param>
        /// <param name="showUI">if the Editor Corotine runner should run a progress UI</param>
        /// <returns>An AsyncDispatch that can be used to track if the coroutine has been dispatched & completed.</returns>
        public static AsyncDispatch Dispatch(IEnumerator task, bool showUI = false)
        {
            // you need this system for this to work! https://gist.github.com/LotteMakesStuff/16b5f2fc108f9a0201950c797d53cfbf
            lock (dispatchQueue) {
                AsyncDispatch dispatch = new AsyncDispatch();

                dispatchQueue.Enqueue(() =>
                {
                    if (showUI)
                    {
                        EditorCoroutineRunner.StartCoroutineWithUI(DispatchCorotine(task, dispatch), "Dispatcher task", false);
                    }
                    else
                    {
                        EditorCoroutineRunner.StartCoroutine(task);
                    }
                });

                return(dispatch);
            }
        }