You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.1 KiB
C#
26 lines
1.1 KiB
C#
1 year ago
|
using System;
|
||
|
using System.Linq;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
class CreateSceneUtility
|
||
|
{
|
||
|
public static void CreateScene(string sceneName, Action delegateToExecute)
|
||
|
{
|
||
|
#if UNITY_EDITOR
|
||
|
string scenePath = "Assets/" + sceneName + ".unity";
|
||
|
var initScene = SceneManager.GetActiveScene();
|
||
|
var list = UnityEditor.EditorBuildSettings.scenes.ToList();
|
||
|
var newScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects, UnityEditor.SceneManagement.NewSceneMode.Additive);
|
||
|
GameObject.DestroyImmediate(Camera.main.GetComponent<AudioListener>());
|
||
|
delegateToExecute();
|
||
|
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
|
||
|
UnityEditor.SceneManagement.EditorSceneManager.UnloadSceneAsync(newScene);
|
||
|
|
||
|
list.Add(new UnityEditor.EditorBuildSettingsScene(scenePath, true));
|
||
|
UnityEditor.EditorBuildSettings.scenes = list.ToArray();
|
||
|
SceneManager.SetActiveScene(initScene);
|
||
|
#endif
|
||
|
}
|
||
|
}
|