From 9f7b897837cc8e000d9dc249987b9231fb2643e9 Mon Sep 17 00:00:00 2001 From: neuecc Date: Sun, 26 Apr 2020 21:49:07 +0900 Subject: [PATCH] Add ObjectIdForDebugger to allow IDE stepin debug, #66, #41 --- Assets/Scenes/SandboxMain.cs | 46 ++++++++++++++++--- .../AsyncUniTaskMethodBuilder.cs | 32 +++++++++++++ .../AsyncUniTaskVoidMethodBuilder.cs | 16 +++++++ 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Assets/Scenes/SandboxMain.cs b/Assets/Scenes/SandboxMain.cs index 1faf82d..0354ea9 100644 --- a/Assets/Scenes/SandboxMain.cs +++ b/Assets/Scenes/SandboxMain.cs @@ -14,13 +14,47 @@ public class SandboxMain : MonoBehaviour public Button cancelButton; CancellationTokenSource cts; - async void Start() + void Start() { - UnityEngine.Debug.Log("DOWNLOAD START:" + Time.frameCount); - - var req = await UnityWebRequest.Get(Path.Combine(Application.streamingAssetsPath, "test.txt")).SendWebRequest(); - - UnityEngine.Debug.Log("DOWNLOAD RESULT:" + Time.frameCount + ", " + req.downloadHandler.text); + okButton.onClick.AddListener(() => + { + FooAsync().Forget(); + }); + cancelButton.onClick.AddListener(() => + { + BarAsync().Forget(); + }); } + + async UniTask FooAsync() + { + // use F10, will crash. + var loop = int.Parse("9"); + await UniTask.DelayFrame(loop); + + Debug.Log("OK"); + await UniTask.DelayFrame(loop); + + Debug.Log("Again"); + + return 10; + } + + async UniTaskVoid BarAsync() + { + var loop = int.Parse("10"); + + + var foo = await UniTask.FromResult(100); + + Debug.Log("OK"); + + + Debug.Log("Again"); + + + } + + } diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs index 586f859..76a358d 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskMethodBuilder.cs @@ -136,6 +136,22 @@ namespace UniRx.Async.CompilerServices public void SetStateMachine(IAsyncStateMachine stateMachine) { } + +#if UNITY_EDITOR + // Important for IDE debugger. + object debuggingId; + private object ObjectIdForDebugger + { + get + { + if (debuggingId == null) + { + debuggingId = new object(); + } + return debuggingId; + } + } +#endif } @@ -268,6 +284,22 @@ namespace UniRx.Async.CompilerServices public void SetStateMachine(IAsyncStateMachine stateMachine) { } + +#if UNITY_EDITOR + // Important for IDE debugger. + object debuggingId; + private object ObjectIdForDebugger + { + get + { + if (debuggingId == null) + { + debuggingId = new object(); + } + return debuggingId; + } + } +#endif } } diff --git a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs index 2fcd55f..bedf7bf 100644 --- a/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs +++ b/Assets/UniRx.Async/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs @@ -84,6 +84,22 @@ namespace UniRx.Async.CompilerServices public void SetStateMachine(IAsyncStateMachine stateMachine) { } + +#if UNITY_EDITOR + // Important for IDE debugger. + object debuggingId; + private object ObjectIdForDebugger + { + get + { + if (debuggingId == null) + { + debuggingId = new object(); + } + return debuggingId; + } + } +#endif } }