1、同步场景
![](https://i-blog.csdnimg.cn/blog_migrate/beb819f0d2d8bab3bb9a6fc68dd1072a.png)
2、异步加载
![](https://i-blog.csdnimg.cn/blog_migrate/7dd28cea9cd60cb65e9c0e15d9271594.png)
public class TestScenesLoad : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
StartCoroutine(Load());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator Load()
{
//异步加载,常用模式,asyncOperation.isDone不会调用
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("scenes/SampleScene");
//一般很少使用复场景加载模式,asyncOperation.isDone此时会被调用
// AsyncOperation asyncOperation = //SceneManager.LoadSceneAsync("scenes/SampleScene",LoadSceneMode.Additive);
asyncOperation.allowSceneActivation = false;
while (asyncOperation.progress < 0.9f)
{
Debug.Log("当前加载的进度为:"+ asyncOperation.progress);
yield return null; //协成中可以等待一帧
}
Debug.Log("当前加载的进度为:" + asyncOperation.progress);
asyncOperation.allowSceneActivation = true;
yield return null; //协成中可以等待一帧
if (asyncOperation.isDone)
{
Debug.Log("加载并跳转完毕");
}
else
{
Debug.Log("还没有加载并跳转完毕");
}
}
}
3、保留物体到下个场景中
![](https://i-blog.csdnimg.cn/blog_migrate/9bd5b291abb28da2dce2a27a3822bffe.png)