Version: 2021.3

EditorSceneManager.LoadSceneInPlayMode

切换到手册
public static SceneManagement.Scene LoadSceneInPlayMode (string path, SceneManagement.LoadSceneParameters parameters);

参数

path 要加载的场景的路径。
parameters 用于加载场景 SceneManagement.LoadSceneParameters 的参数。

返回

Scene 正在加载的场景。

描述

此方法允许在编辑器中的播放模式期间加载场景,而不需要将场景包含在 Build Settings 的场景列表中。

The use case for this is to emulate Asset bundles while loading scenes in play mode in the editor. When including a scene in an asset bundle, you don't add the scene to build settings. This means you can't load the scene during play mode using the normal LoadScene method. Using this method instead of LoadScene allows you to load the scene during play mode without requiring it to be in the Build Settings scene list. This means your code needs to detect whether the game is running in the editor or not, and use this method (LoadSceneInPlayMode) when in the editor, and LoadScene when in the built version.

请注意,此函数与 SceneManager.LoadScene 的行为相同,这意味着加载不会立即发生,但保证在下一帧中完成。此行为还意味着返回的场景的状态设置为 Loading。