Fix DelayType.Realtime does not work when use BuildPlayer in UnityEditor

master
neuecc 2021-01-07 16:40:41 +09:00
parent 5ced0a1d4b
commit 71879266ac
6 changed files with 64 additions and 1 deletions

2
.gitignore vendored
View File

@ -257,3 +257,5 @@ src/UniTask/Assembly-CSharp.Player.csproj
src/UniTask/Unity.EditorCoroutines.Editor.csproj
src/UniTask/.vsconfig
src/UniTask/Logs/ApiUpdaterCheck.txt

View File

@ -18,6 +18,8 @@ namespace Cysharp.Threading.Tasks.Internal
public TimeSpan Elapsed => TimeSpan.FromTicks(this.ElapsedTicks);
public bool IsInvalid => startTimestamp == 0;
public long ElapsedTicks
{
get

View File

@ -726,6 +726,12 @@ namespace Cysharp.Threading.Tasks
return false;
}
if (stopwatch.IsInvalid)
{
core.TrySetResult(AsyncUnit.Default);
return false;
}
if (stopwatch.ElapsedTicks >= delayTimeSpanTicks)
{
core.TrySetResult(AsyncUnit.Default);

View File

@ -0,0 +1,41 @@
#if UNITY_EDITOR
using System;
using Cysharp.Threading.Tasks;
using UnityEditor;
using UnityEngine;
public class Test1
{
[MenuItem("Test/Test1")]
public static async UniTaskVoid TestFunc()
{
await DoSomeThing();
string[] scenes = new string[]
{
"Assets/Scenes/SandboxMain.unity",
};
try
{
Debug.Log("Build Begin");
BuildPipeline.BuildPlayer(scenes, Application.dataPath + "../target", BuildTarget.StandaloneWindows, BuildOptions.CompressWithLz4);
Debug.Log("Build After");
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
public static async UniTask DoSomeThing()
{
Debug.Log("Dosomething");
await UniTask.Delay(1500, DelayType.Realtime);
Debug.Log("Dosomething 2");
await UniTask.Delay(1000, DelayType.Realtime);
Debug.Log("Dosomething 3");
}
}
#endif

View File

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

View File

@ -578,6 +578,7 @@ public class SandboxMain : MonoBehaviour
Debug.Log("BEFORE:" + Time.frameCount);
await UniTask.Yield();
// await UniTask.Yield(PlayerLoopTiming.LastTimeUpdate);
Debug.Log("AFTER:" + Time.frameCount);