From 265f88584bf740a227e7a06e401b5fe2e8bc236a Mon Sep 17 00:00:00 2001 From: neuecc Date: Sat, 6 Jun 2020 14:21:31 +0900 Subject: [PATCH] store application.datapath on initialize #86 --- .../Runtime/Internal/DiagnosticsExtensions.cs | 2 +- .../UniTask/Runtime/PlayerLoopHelper.cs | 7 ++++++ src/UniTask/Assets/Scenes/SandboxMain.cs | 22 ++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs index 08a6fe4..34ff1e2 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs @@ -239,7 +239,7 @@ namespace Cysharp.Threading.Tasks.Internal } else { - var fname = fi.FullName.Replace(Path.DirectorySeparatorChar, '/').Replace(Application.dataPath, ""); + var fname = fi.FullName.Replace(Path.DirectorySeparatorChar, '/').Replace(PlayerLoopHelper.ApplicationDataPath, ""); var withAssetsPath = "Assets/" + fname; return "" + withAssetsPath + ":" + line + ""; } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs index df9c000..13fec6c 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs @@ -92,8 +92,10 @@ namespace Cysharp.Threading.Tasks { public static SynchronizationContext UnitySynchronizationContext => unitySynchronizationContetext; public static int MainThreadId => mainThreadId; + internal static string ApplicationDataPath => applicationDataPath; static int mainThreadId; + static string applicationDataPath; static SynchronizationContext unitySynchronizationContetext; static ContinuationQueue[] yielders; static PlayerLoopRunner[] runners; @@ -177,6 +179,11 @@ namespace Cysharp.Threading.Tasks // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; mainThreadId = Thread.CurrentThread.ManagedThreadId; + try + { + applicationDataPath = Application.dataPath; + } + catch { } #if UNITY_EDITOR && UNITY_2019_3_OR_NEWER // When domain reload is disabled, re-initialization is required when entering play mode; diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 916064b..f55f569 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -302,15 +302,25 @@ public class SandboxMain : MonoBehaviour return 10; } + async UniTask Ex() + { + await UniTask.Yield(); + //throw new Exception(); + await UniTask.Delay(TimeSpan.FromSeconds(15)); + return 0; + } + void Start() { - //_ = UniTask.Run(async () => - //{ - // var watch = System.Diagnostics.Stopwatch.StartNew(); - // await UniTask.Delay(new TimeSpan(0, 0, seconds: 10)); - // Debug.Log(watch.Elapsed); - //}); + _ = Ex(); + + _ = UniTask.Run(async () => + { + var watch = System.Diagnostics.Stopwatch.StartNew(); + await UniTask.Delay(new TimeSpan(0, 0, seconds: 10)); + Debug.Log(watch.Elapsed); + }); //return; //await UniTask.SwitchToMainThread();