mirror of https://github.com/Cysharp/UniTask
fix in UnityEditor performance issue
parent
6dfb969015
commit
f60d2c51fb
|
@ -0,0 +1,28 @@
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public static class EditorRunnerChecker
|
||||||
|
{
|
||||||
|
[MenuItem("Tools/UniTaskEditorRunnerChecker")]
|
||||||
|
public static void RunUniTaskAsync()
|
||||||
|
{
|
||||||
|
RunCore().Forget();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async UniTaskVoid RunCore()
|
||||||
|
{
|
||||||
|
Debug.Log("Start, Wait 5 seconds. deltaTime?" + Time.deltaTime);
|
||||||
|
|
||||||
|
await UniTask.Delay(TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
|
Debug.Log("End, Wait 5 seconds. deltaTime?" + Time.deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e51b78c06cb410f42b36e0af9de3b065
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -200,6 +200,7 @@ namespace Cysharp.Threading.Tasks
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
[InitializeOnLoadMethod]
|
[InitializeOnLoadMethod]
|
||||||
static void InitOnEditor()
|
static void InitOnEditor()
|
||||||
{
|
{
|
||||||
|
@ -210,17 +211,34 @@ namespace Cysharp.Threading.Tasks
|
||||||
EditorApplication.update += ForceEditorPlayerLoopUpdate;
|
EditorApplication.update += ForceEditorPlayerLoopUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double beforeCalledTime;
|
||||||
|
|
||||||
private static void ForceEditorPlayerLoopUpdate()
|
private static void ForceEditorPlayerLoopUpdate()
|
||||||
{
|
{
|
||||||
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling ||
|
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating)
|
||||||
EditorApplication.isUpdating)
|
|
||||||
{
|
{
|
||||||
// Not in Edit mode, don't interfere
|
// Not in Edit mode, don't interfere
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//force unity to update PlayerLoop callbacks
|
// EditorApplication.QueuePlayerLoopUpdate causes performance issue, don't call directly.
|
||||||
EditorApplication.QueuePlayerLoopUpdate();
|
// EditorApplication.QueuePlayerLoopUpdate();
|
||||||
|
|
||||||
|
if (yielders != null)
|
||||||
|
{
|
||||||
|
foreach (var item in yielders)
|
||||||
|
{
|
||||||
|
if (item != null) item.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runners != null)
|
||||||
|
{
|
||||||
|
foreach (var item in runners)
|
||||||
|
{
|
||||||
|
if (item != null) item.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue