Skip to content

Instantly share code, notes, and snippets.

@mosluce
Last active December 12, 2020 19:48
Show Gist options
  • Select an option

  • Save mosluce/21d56e6b796ff8c7e649bcbe13cd79d1 to your computer and use it in GitHub Desktop.

Select an option

Save mosluce/21d56e6b796ff8c7e649bcbe13cd79d1 to your computer and use it in GitHub Desktop.
using System.Reflection;
using System.Threading;
using UnityEditor;
using UnityEngine;
public static class EditorAsyncPump {
[InitializeOnLoadMethod]
static void Initialize() {
Debug.Log("Pump Initialize");
EditorApplication.update += ExecuteContinuations;
}
static void ExecuteContinuations() {
if (EditorApplication.isPlayingOrWillChangePlaymode) {
// Not in Edit mode, don't interfere
return;
}
var context = SynchronizationContext.Current;
if (_execMethod == null) {
_execMethod = context.GetType().GetMethod("Exec", BindingFlags.NonPublic | BindingFlags.Instance);
}
_execMethod.Invoke(context, null);
}
static MethodInfo _execMethod;
}
// 來源: https://forum.unity.com/threads/async-await-in-editor-script.481276/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment