版本:Unity 6 (6000.0)
语言中文
  • C#

EditorBuildSettings.scenes

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但会阅读用户提出的每个变更建议,并在适用情况下进行更新。

关闭

提交失败

由于某种原因,无法提交您建议的更改。请在几分钟后<a>重试</a>。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

public static EditorBuildSettingsScene[] scenes;

描述

应该包含在构建中的场景列表。

显示在构建设置窗口中的场景列表。您可以修改此列表,设置应包含在构建中的场景。

注意:直接调用BuildPipeline.BuildPlayer时,可以使用BuildPlayerOptions.scenes代替此属性。

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(); } }