Created
March 1, 2018 03:56
-
-
Save andyman/d4f392510fb94a91d7cbf00fab7a13be to your computer and use it in GitHub Desktop.
Automatically save the Unity scene when pressing play.
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
// Place inside your Editor folder inside of Assets for it to save the current scene(s) when you run. | |
// The folder must be called "Editor", but can be nested within something else, e.g. Scripts/Editor | |
using System; | |
using System.IO; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
[InitializeOnLoad] | |
public class OnUnityLoad | |
{ | |
static OnUnityLoad() | |
{ | |
EditorApplication.playModeStateChanged += (PlayModeStateChange change) => | |
{ | |
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) | |
{ | |
Debug.Log("Auto-Saving scene(s) before entering Play mode."); | |
EditorSceneManager.SaveOpenScenes(); | |
AssetDatabase.SaveAssets(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment