fix in UnityEditor performance issue

master
neuecc 2020-05-24 03:27:05 +09:00
parent 6dfb969015
commit f60d2c51fb
3 changed files with 63 additions and 6 deletions

View File

@ -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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e51b78c06cb410f42b36e0af9de3b065
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -200,6 +200,7 @@ namespace Cysharp.Threading.Tasks
#if UNITY_EDITOR
[InitializeOnLoadMethod]
static void InitOnEditor()
{
@ -210,17 +211,34 @@ namespace Cysharp.Threading.Tasks
EditorApplication.update += ForceEditorPlayerLoopUpdate;
}
static double beforeCalledTime;
private static void ForceEditorPlayerLoopUpdate()
{
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling ||
EditorApplication.isUpdating)
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating)
{
// Not in Edit mode, don't interfere
return;
}
//force unity to update PlayerLoop callbacks
EditorApplication.QueuePlayerLoopUpdate();
// EditorApplication.QueuePlayerLoopUpdate causes performance issue, don't call directly.
// 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