Created
January 3, 2018 04:50
-
-
Save calderarchinuk/7cc70100065c4386f33ffa47b9e91ec1 to your computer and use it in GitHub Desktop.
add all scene files in project to build settings
This file contains 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 UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
public partial class BonusMenuItems | |
{ | |
[MenuItem("Tools/Add All Scenes to Build")] | |
static void AddAllScenesToBuild() | |
{ | |
//TODO put this code into some function that can be called from the build process | |
List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>(); | |
GameObject.FindObjectOfType<GameInstance>().Scenes.Clear(); | |
foreach (var v in AssetDatabase.FindAssets("t:scene")) | |
{ | |
string path = AssetDatabase.GUIDToAssetPath(v); | |
var bundle = AssetDatabase.GetImplicitAssetBundleName(path); | |
if (!string.IsNullOrEmpty(bundle)) | |
{ | |
Debug.Log("Found scene "+path+" in bundle "+ bundle+". do not add to build settings!"); | |
continue; | |
} | |
string[] parts = path.Split('/'); | |
string sceneName = parts[parts.Length-1].Replace(".unity",""); | |
GameObject.FindObjectOfType<GameInstance>().Scenes.Add(sceneName); | |
editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(path, true)); | |
} | |
Debug.Log("Added " + editorBuildSettingsScenes.Count + " scenes to build!"); | |
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment