UniTask/Assets/Scenes/SandboxMain.cs

61 lines
1.0 KiB
C#
Raw Normal View History

2019-05-30 18:41:23 +08:00
using System;
using System.Collections;
2019-05-19 23:14:47 +08:00
using System.Collections.Generic;
2020-04-15 14:23:23 +08:00
using System.IO;
2019-05-30 18:41:23 +08:00
using System.Threading;
2019-05-19 23:14:47 +08:00
using UniRx.Async;
using UnityEngine;
2019-05-30 18:41:23 +08:00
using UnityEngine.Networking;
using UnityEngine.UI;
2019-05-19 23:14:47 +08:00
public class SandboxMain : MonoBehaviour
{
2019-05-30 18:41:23 +08:00
public Button okButton;
public Button cancelButton;
CancellationTokenSource cts;
2019-05-19 23:14:47 +08:00
void Start()
2019-05-19 23:14:47 +08:00
{
okButton.onClick.AddListener(() =>
{
FooAsync().Forget();
});
cancelButton.onClick.AddListener(() =>
{
BarAsync().Forget();
});
}
async UniTask<int> 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");
2019-05-30 18:41:23 +08:00
2020-04-15 14:23:23 +08:00
2019-05-19 23:14:47 +08:00
}
2019-05-19 23:14:47 +08:00
}
2019-05-30 18:41:23 +08:00