Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorBuildSettings.scenes

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static var scenes: EditorBuildSettingsScene[];
public static EditorBuildSettingsScene[] scenes;

Description

The list of Scenes that should be included in the build. This is the same list of Scenes that is shown in the Build Settings window. You can modify this list to set up which Scenes should be included in the build.

#pragma strict
import System.Collections.Generic;

public class ExampleWindow extends EditorWindow { var m_SceneAssets: List.<SceneAsset> = new List.<SceneAsset>(); // Add menu item named "Example Window" to the Window menu @MenuItem("Window/Example Window") public static function ShowWindow() { //Show existing window instance. If one doesn't exist, make one. EditorWindow.GetWindow(ExampleWindow); } function OnGUI() { GUILayout.Label("Scenes to include in build:", EditorStyles.boldLabel); for (var i: int = 0; i < m_SceneAssets.Count; ++i) { m_SceneAssets[i] = EditorGUILayout.ObjectField(m_SceneAssets[i], SceneAsset, false) as SceneAsset; } if (GUILayout.Button("Add")) { m_SceneAssets.Add(null); } GUILayout.Space(8); if (GUILayout.Button("Apply To Build Settings")) { SetEditorBuildSettingsScenes(); } } public function SetEditorBuildSettingsScenes() { // Find valid Scene paths and make a list of EditorBuildSettingsScene var editorBuildSettingsScenes: List.<EditorBuildSettingsScene> = new List.<EditorBuildSettingsScene>(); for (var sceneAsset: SceneAsset in m_SceneAssets) { var scenePath: String = AssetDatabase.GetAssetPath(sceneAsset); if (!String.IsNullOrEmpty(scenePath)) editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(scenePath, true)); } // Set the Build Settings window Scene list EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray(); } }
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ExampleWindow : EditorWindow { List<SceneAsset> m_SceneAssets = new List<SceneAsset>();

// Add menu item named "Example Window" to the Window menu [MenuItem("Window/Example Window")] public static void ShowWindow() { //Show existing window instance. If one doesn't exist, make one. EditorWindow.GetWindow(typeof(ExampleWindow)); }

void OnGUI() { GUILayout.Label("Scenes to include in build:", EditorStyles.boldLabel); for (int i = 0; i < m_SceneAssets.Count; ++i) { m_SceneAssets[i] = (SceneAsset)EditorGUILayout.ObjectField(m_SceneAssets[i], typeof(SceneAsset), false); } if (GUILayout.Button("Add")) { m_SceneAssets.Add(null); }

GUILayout.Space(8);

if (GUILayout.Button("Apply To Build Settings")) { SetEditorBuildSettingsScenes(); } }

public void SetEditorBuildSettingsScenes() { // Find valid Scene paths and make a list of EditorBuildSettingsScene List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>(); foreach (var sceneAsset in m_SceneAssets) { string scenePath = AssetDatabase.GetAssetPath(sceneAsset); if (!string.IsNullOrEmpty(scenePath)) editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(scenePath, true)); }

// Set the Build Settings window Scene list EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray(); } }