Last active
May 14, 2018 01:19
-
-
Save sinistersnare/1f397c66d3290c2fde437ddcd5bc44d3 to your computer and use it in GitHub Desktop.
Auto saves current Unity scene when entering play mode.
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
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
[InitializeOnLoad] | |
public class AutoSaveSceneOnPlay: ScriptableObject { | |
static AutoSaveSceneOnPlay() { | |
EditorApplication.playModeStateChanged += OnStateChanged; | |
} | |
private static void OnStateChanged(PlayModeStateChange state) { | |
Scene currentScene = SceneManager.GetActiveScene(); | |
if (state == PlayModeStateChange.ExitingEditMode) { | |
Debug.Log("Auto-Saving scene before entering Play mode: " + currentScene.name); | |
bool saveOK = EditorSceneManager.SaveScene(currentScene, currentScene.path); | |
if (!saveOK) Debug.Log("SAVE FAILED"); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment