mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-17 20:50:11 +00:00
complete infrastructure
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UniRx.Async;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@@ -12,15 +13,111 @@ public class SandboxMain : MonoBehaviour
|
||||
{
|
||||
public Button okButton;
|
||||
public Button cancelButton;
|
||||
public Text text;
|
||||
|
||||
CancellationTokenSource cts;
|
||||
|
||||
async void Start()
|
||||
UniTaskCompletionSource2 ucs;
|
||||
|
||||
void Start()
|
||||
{
|
||||
UnityEngine.Debug.Log("DOWNLOAD START:" + Time.frameCount);
|
||||
// Setup unobserverd tskexception handling
|
||||
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
||||
|
||||
var req = await UnityWebRequest.Get(Path.Combine(Application.streamingAssetsPath, "test.txt")).SendWebRequest();
|
||||
// Optional: disable ExecutionContext if you don't use AsyncLocal.
|
||||
//if (!ExecutionContext.IsFlowSuppressed())
|
||||
//{
|
||||
// ExecutionContext.SuppressFlow();
|
||||
//}
|
||||
|
||||
UnityEngine.Debug.Log("DOWNLOAD RESULT:" + Time.frameCount + ", " + req.downloadHandler.text);
|
||||
//// Optional: disable SynchronizationContext(to boostup performance) if you completely use UniTask only
|
||||
//SynchronizationContext.SetSynchronizationContext(null);
|
||||
|
||||
// -----
|
||||
|
||||
Application.logMessageReceived += Application_logMessageReceived;
|
||||
|
||||
|
||||
ucs = new UniTaskCompletionSource2();
|
||||
|
||||
okButton.onClick.AddListener(UniTask.VoidUnityAction(async () =>
|
||||
{
|
||||
await OuterAsync(true);
|
||||
}));
|
||||
|
||||
cancelButton.onClick.AddListener(async () =>
|
||||
{
|
||||
text.text = "";
|
||||
|
||||
ucs.SetResult();
|
||||
|
||||
await ucs.Task;
|
||||
});
|
||||
}
|
||||
|
||||
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
||||
{
|
||||
text.text += "\n" + condition;
|
||||
}
|
||||
|
||||
async UniTask2 OuterAsync(bool b)
|
||||
{
|
||||
UnityEngine.Debug.Log("START OUTER");
|
||||
|
||||
await InnerAsync(b);
|
||||
await InnerAsync(b);
|
||||
|
||||
UnityEngine.Debug.Log("END OUTER");
|
||||
|
||||
// throw new InvalidOperationException("NAZO ERROR!?"); // error!?
|
||||
}
|
||||
|
||||
async UniTask2 InnerAsync(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
UnityEngine.Debug.Log("Start delay:" + Time.frameCount);
|
||||
await UniTask2.DelayFrame(60);
|
||||
UnityEngine.Debug.Log("End delay:" + Time.frameCount);
|
||||
await UniTask2.DelayFrame(60);
|
||||
UnityEngine.Debug.Log("Onemore end delay:" + Time.frameCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
//UnityEngine.Debug.Log("Empty END");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
||||
{
|
||||
// e.SetObserved();
|
||||
// or other custom write code.
|
||||
UnityEngine.Debug.LogError("Unobserved:" + e.Exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user