当前位置:   article > 正文

UniTask官方使用方法_tounitask()

tounitask()

Getting started

  1. // extension awaiter/methods can be used by this namespace
  2. using Cysharp.Threading.Tasks;
  3. // You can return type as struct UniTask<T>(or UniTask), it is unity specialized lightweight alternative of Task<T>
  4. // zero allocation and fast excution for zero overhead async/await integrate with Unity
  5. async UniTask<string> DemoAsync()
  6. {
  7. // You can await Unity's AsyncObject
  8. var asset = await Resources.LoadAsync<TextAsset>("foo");
  9. var txt = (await UnityWebRequest.Get("https://...").SendWebRequest()).downloadHandler.text;
  10. await SceneManager.LoadSceneAsync("scene2");
  11. // .WithCancellation enables Cancel, GetCancellationTokenOnDestroy synchornizes with lifetime of GameObject
  12. var asset2 = await Resources.LoadAsync<TextAsset>("bar").WithCancellation(this.GetCancellationTokenOnDestroy());
  13. // .ToUniTask accepts progress callback(and all opti
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/95508
推荐阅读
相关标签
  

闽ICP备14008679号