LoadSceneMode

enumeration

Switch to Manual

Description

在播放器中加载场景时使用。

通过 LoadSceneMode 选择在使用 SceneManager.LoadScene 时加载哪种类型的场景。可用模式为单模式和附加模式。

单模式将加载一个标准的 Unity 场景,该场景将独立显示在 Hierarchy 窗口中。附加模式将加载一个显示在 Hierarchy 窗口的场景,而窗口中同时还包含其他活动场景。


using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour { void OnGUI() { //This displays a Button on the screen at position (20,30), width 150 and height 50. The button’s text reads the last parameter. Press this for the SceneManager to load the Scene. if (GUI.Button(new Rect(20, 30, 150, 30), "Other Scene Single")) { //The SceneManager loads your new Scene as a single Scene (not overlapping). This is Single mode. SceneManager.LoadScene("YourScene", LoadSceneMode.Single); }

//Whereas pressing this Button loads the Additive Scene. if (GUI.Button(new Rect(20, 60, 150, 30), "Other Scene Additive")) { //SceneManager loads your new Scene as an extra Scene (overlapping the other). This is Additive mode. SceneManager.LoadScene("YourScene", LoadSceneMode.Additive); } } }

Variables

Single关闭所有当前加载的场景并加载一个场景。
Additive将场景添加到当前加载的场景。