public static EditorBuildSettingsScene[] scenes ;

描述

应包含在构建中的场景列表。 这与 Build Settings 窗口中显示的场景列表相同。您可以修改此列表,以设置应在构建中包含哪些场景。

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(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961