Last active
June 20, 2018 13:14
-
-
Save nicoplv/0ba7924abe82356d9bbcbf119c0a4c7f to your computer and use it in GitHub Desktop.
Editor script to make Play button always start a main scene in Unity 3D (works only with 2017.2 or +)
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 UnityEditor.SceneManagement; | |
using UnityEngine; | |
namespace SmartEditors | |
{ | |
[InitializeOnLoad] | |
public class PlayFromScene : Editor | |
{ | |
[MenuItem("Tools/Editor/Play From Scene/Set Main Scene", false, 0)] | |
public static void SetScene() | |
{ | |
SceneAsset playModeStartScene = AssetDatabase.LoadAssetAtPath<SceneAsset>(EditorSceneManager.GetActiveScene().path); | |
if (playModeStartScene != null) | |
EditorSceneManager.playModeStartScene = playModeStartScene; | |
else | |
Debug.Log("Scene not saved!"); | |
} | |
[MenuItem("Tools/Editor/Play From Scene/Unset Main Scene", false, 1)] | |
public static void UnsetScene() | |
{ | |
EditorSceneManager.playModeStartScene = null; | |
} | |
[MenuItem("Tools/Editor/Play From Scene/Unset Main Scene", true, 1)] | |
public static bool UnsetSceneValidate() | |
{ | |
return EditorSceneManager.playModeStartScene != null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, I tested it and it does work indeed :)
The API change was added in 2017.1
https://docs.unity3d.com/2017.1/Documentation/ScriptReference/SceneManagement.EditorSceneManager-playModeStartScene.html