Last active
February 12, 2020 13:48
-
-
Save monry/0314c81a9f48d14cd6ceffad44f4c49c to your computer and use it in GitHub Desktop.
Editor script to automatically add scenes to Scenes in Build
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 System.Linq; | |
using UnityEditor; | |
namespace Foo | |
{ | |
[InitializeOnLoad] | |
public static class ScenesInBuildConfigurator | |
{ | |
private static string SceneName { get; } = "Bar"; | |
private static string SceneGUID { get; } = AssetDatabase | |
.FindAssets($"t:Scene {SceneName}") | |
.FirstOrDefault(); | |
static ScenesInBuildConfigurator() | |
{ | |
if (ContainsScene()) | |
{ | |
return; | |
} | |
var scenes = EditorBuildSettings.scenes.ToList(); | |
scenes.Add(new EditorBuildSettingsScene(AssetDatabase.GUIDToAssetPath(SceneGUID), true)); | |
EditorBuildSettings.scenes = scenes.ToArray(); | |
} | |
private static bool ContainsScene() | |
{ | |
return EditorBuildSettings | |
.scenes | |
.Any(x => x.guid.ToString() == SceneGUID); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment