1、同步场景
![](https://img-blog.csdnimg.cn/4ef0747c864a4c2d922e40e8188e47eb.png)
2、异步加载
![](https://img-blog.csdnimg.cn/dd56ebf917d34b1aa8f33acbac50fc13.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://img-blog.csdnimg.cn/7125fcebba6d4d7882956c7bdbe60d66.png)