Version: 2022.3

EditorSceneManager.playModeStartScene

切换到手册
public static SceneAsset playModeStartScene ;

描述

启动播放模式时加载此场景资源。

如果将此属性设置为一个场景资源,那么在您启动播放模式时,Unity 加载的将是此场景资源而非编辑器中当前打开的场景。

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

public class TestWindow : EditorWindow { void OnGUI() { // Use the Object Picker to select the start SceneAsset EditorSceneManager.playModeStartScene = (SceneAsset)EditorGUILayout.ObjectField(new GUIContent("Start Scene"), EditorSceneManager.playModeStartScene, typeof(SceneAsset), false);

// Or set the start Scene from code var scenePath = "Assets/Scene3.unity"; if (GUILayout.Button("Set start Scene: " + scenePath)) SetPlayModeStartScene(scenePath); }

void SetPlayModeStartScene(string scenePath) { SceneAsset myWantedStartScene = AssetDatabase.LoadAssetAtPath<SceneAsset>(scenePath); if (myWantedStartScene != null) EditorSceneManager.playModeStartScene = myWantedStartScene; else Debug.Log("Could not find Scene " + scenePath); }

[MenuItem("Test/Open")] static void Open() { GetWindow<TestWindow>(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961