Last active
October 29, 2020 10:52
-
-
Save SiarheiPilat/0a0eff9a394af88db0de81483d49faba to your computer and use it in GitHub Desktop.
Add open/active scene to the build settings as last scene or (!!!) second to last scene using menu item or shortcuts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
using UnityEditor.SceneManagement; | |
// inspired by https://answers.unity.com/questions/205742/adding-scene-to-build.html?_ga=2.184209894.1575122923.1603913761-831749454.1600446627 | |
public static class AddSceneToBuildSettingsShortcut | |
{ | |
[MenuItem("Game/Add scene as last build scene &a")] | |
private static void AddAsLastBuildScene() | |
{ | |
EditorBuildSettingsScene[] original = EditorBuildSettings.scenes; | |
EditorBuildSettingsScene[] newSettings = new EditorBuildSettingsScene[original.Length + 1]; | |
System.Array.Copy(original, newSettings, original.Length); | |
EditorBuildSettingsScene sceneToAdd = new EditorBuildSettingsScene(EditorSceneManager.GetActiveScene().path, true); | |
newSettings[newSettings.Length - 1] = sceneToAdd; | |
EditorBuildSettings.scenes = newSettings; | |
Debug.Log("Added scene " + EditorSceneManager.GetActiveScene().name + " as the last scene in build settings"); | |
} | |
[MenuItem("Game/Add scene as second to last build scene #&a")] | |
private static void AddAsSecondToLastBuildScene() | |
{ | |
EditorBuildSettingsScene[] original = EditorBuildSettings.scenes; | |
EditorBuildSettingsScene[] newSettings = new EditorBuildSettingsScene[original.Length + 1]; | |
System.Array.Copy(original, newSettings, original.Length); | |
EditorBuildSettingsScene sceneToAdd = new EditorBuildSettingsScene(EditorSceneManager.GetActiveScene().path, true); | |
newSettings[newSettings.Length - 1] = newSettings[newSettings.Length - 2]; // swapping the scenes | |
newSettings[newSettings.Length - 2] = sceneToAdd; | |
EditorBuildSettings.scenes = newSettings; | |
Debug.Log("Added scene " + EditorSceneManager.GetActiveScene().name + " as second to last scene in build settings"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment