Hi!!
Does someone know if there is a way to “drop” scenes into the Scenes In Build window from script?
I usually drop all scenes manually before each release, but it starts to be pretty heavy to repeat the drag and drop for hundred of scenes
I found the “EditorBuildSettings.scenes” function into the scripting doc, but there is not C# example :
I really do not have any idea on how to use it and interact with Unity itself O_o.
A quick example or URL about tool scripting for Unity would be ok to start…
I didn’t found much thing about it
Thank you much!
Thanks lamont!
Here is the code with some customization and loop process :
using UnityEngine;
using UnityEditor;
public class AddScenesToBuild : EditorWindow
{
[MenuItem ("FolioTools/AddScenesToBuild")]
static void Init ()
{
string MainFolder = "Assets/Application/Scenes/";
string SceneType = ".unity";
string [] ScenesList = new string [] { "2006/2006_Colossus/Scene_Colossus_CH_Lycan_A",
"2006/2006_Colossus/Scene_Colossus_CH_Tiamate_A",
"2006/2006_Colossus/Scene_Colossus_CR_Kokopeli_A",
"2006/2006_Colossus/Scene_Colossus_CR_Marmotte_A",
"2006/2006_Colossus/Scene_Colossus_CR_TitanDeNuit_A",};
EditorBuildSettingsScene[] original = EditorBuildSettings.scenes;
EditorBuildSettingsScene[] newSettings = new EditorBuildSettingsScene[original.Length + ScenesList.Length];
System.Array.Copy(original, newSettings, original.Length);
Debug.Log ("Original Build Lenght = " + original.Length);
Debug.Log ("New Build Lenght = " + newSettings.Length);
int i = 0;
int index = original.Length;
for (i = 0; i < ScenesList.Length; i ++)
{
Debug.Log ("i = " + i);
EditorBuildSettingsScene sceneToAdd = new EditorBuildSettingsScene(MainFolder + ScenesList[i] + SceneType, true);
newSettings[index] = sceneToAdd;
index ++;
}
EditorBuildSettings.scenes = newSettings;
}
}
3 Likes
Your code doesn’t work dude
it’s super oldish O_O… like 6years ago… maybe a few things changed since!?..
2 Likes
I actually got it working yesterday to fit what I wanted it to do (Thank you!), but now im getting a NullReferenceException at your line 40… I’m completely new to unity as of a week ago, so I’ll see if I can fix it. It literally just worked yesterday.
I have a version here which gets all .unity files from a specified folder and adds them to the build settings:
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class Add_Scenes : EditorWindow
{
[MenuItem ("MyTools/AddScenesToBuild")]
static void Init ()
{
List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>();
List<string> SceneList = new List<string> ();
string MainFolder = "Assets/Scenes";
DirectoryInfo d = new DirectoryInfo(@MainFolder);
FileInfo[] Files = d.GetFiles("*.unity"); //Getting unity files
foreach(FileInfo file in Files )
{
Debug.Log ("file name:" + file.Name);
SceneList.Add(file.Name);
}
int i = 0;
for (i = 0; i < SceneList.Count; i ++)
{
string scenePath = MainFolder + "/" + SceneList[i];
Debug.Log ("i = " + i);
Debug.Log("scene path:" + scenePath);
editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(scenePath, true));
}
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
}
}
2 Likes
sudogetpizza:
I have a version here which gets all .unity files from a specified folder and adds them to the build settings:
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class Add_Scenes : EditorWindow
{
[MenuItem ("MyTools/AddScenesToBuild")]
static void Init ()
{
List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>();
List<string> SceneList = new List<string> ();
string MainFolder = "Assets/Scenes";
DirectoryInfo d = new DirectoryInfo(@MainFolder);
FileInfo[] Files = d.GetFiles("*.unity"); //Getting unity files
foreach(FileInfo file in Files )
{
Debug.Log ("file name:" + file.Name);
SceneList.Add(file.Name);
}
int i = 0;
for (i = 0; i < SceneList.Count; i ++)
{
string scenePath = MainFolder + "/" + SceneList[i];
Debug.Log ("i = " + i);
Debug.Log("scene path:" + scenePath);
editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(scenePath, true));
}
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
}
}
I have a question : where do you put this file ? is it launched whenever we build the project ? thx in advance
EDIT: I guess every script inheriting from UnityEditor is initialised before the build.
Old thread but first google result.
For the record, there is an example in the Unity docs about doing just this: