SW-Wiktor-Bombola/SW-Unity/Library/PackageCache/com.unity.ugui@1.0.0/Tests/Runtime/Canvas/CreateSceneUtility.cs

25 lines
996 B
C#
Raw Normal View History

2021-12-04 15:15:29 +01:00
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);
list.Add(new UnityEditor.EditorBuildSettingsScene(scenePath, true));
UnityEditor.EditorBuildSettings.scenes = list.ToArray();
SceneManager.SetActiveScene(initScene);
#endif
}
}