UniTask
1. 异步操作转化为 unitask
1.1 异步加载资源
private async void OnClickLoadText()
{
var loadOperation = Resources.LoadAsync<TextAsset>("test");
var text = await loadOperation;
TargetText.text = ((TextAsset) text).text;
}public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperation)
{
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
return new ResourceRequestAwaiter(asyncOperation);
}public UnityEngine.Object GetResult()
{
if (continuationAction != null)
{
asyncOperation.completed -= continuationAction;
continuationAction = null;
var result = asyncOperation.asset;
asyncOperation = null;
return result;
}
else
{
var result = asyncOperation.asset;
asyncOperation = null;
return result;
}
}1.2 异步加载场景
1.3 网络请求的异步操作
2.Delay & Wait
Last updated