SceneAutoLoader

Author: User:Yoyo

Description
This editor script lets you work in one scene but load another one when you press play in the Unity Editor. This functionality is useful when you are working on a scene for a level or section of the world, but you need to load a different "master scene" in order to play your game. By automatically switching to and from the master scene when you press play in the editor, the scene auto-loader speeds up your workflow.

This script is a complete reimplementation of an idea discussed on this forum thread.

Usage
Save the script below as Assets/Editor/SceneAutoLoader.cs. The script will be automatically activated when you open your project, creating a "Scene Autoload" sub-menu on the Unity Editor File menu.

The menu options are:
 * Select Master Scene... - choose the scene that should be loaded when you press play
 * Load Master On Play - select this to auto-load your master scene (if greyed out then this is the active option)
 * Don't Load Master On Play - select this to disable auto-load of your master scene (if greyed out then this is the active option)

This script is tested, but as with all community scripts, usage is at your own risk.

How It Works
The script uses InitializeOnLoad to auto-run its static constructor, which attaches a callback to EditorApplication.playmodeStateChanged. This callback will load the designated master scene when the user presses play, and reload the previous scene when they press stop.

Menu items are created to select the master scene, using EditorUtility.OpenFilePanel, and to enabled and disable auto-loading of the master scene.

Before auto-loading the master scene, EditorApplication.SaveCurrentSceneIfUserWantsTo is used to make sure edits in the sub-scene aren't thrown away without the user knowing. If the user chooses to cancel the save scene operation then the editor play operation is also cancelled.

EditorPrefs are used to remember the user's auto-loading preferences.

Update
March 7, 2013: Initial revision.

Proposed Patch
This script is very useful with a single project, but wasn't working nicely with multiple projects so I made a small one line code addition. This addition doesn't help with all projects, but will work when switching between projects with the same scene structure (eg. the master scene is named the same). Add this code in SelectMasterScene right after masterScene is first declared but before the conditional:

masterScene = masterScene.Replace(Application.dataPath, "Assets/");	//project relative instead of absolute path