Unity 异步加载
通过Addressable进行资源加载
异步等待库下载地址:
https://github.com/svermeulen/Unity3dAsyncAwaitUtil/releases
携程转异步的写法举例:
携程写法:
IEnumerator Start()
{
StartCorutine(LoadResource(“XXX”));
}
IEnumerator LoadResource(string xxx)
{
yield return new WaitForSeconds(3);
}
异步写法:
async void Start()
{
await LoadResource(“XXX”);
}
async Task LoadResource(string xxx)
{
//这里new 了一个对象 会返回Task。所以这个方法返回值必须是Task。
await new WaitForSeconds(3);
}
注意
async: 用来标记异步方法。
await:用来执行异步等待。