Created
September 28, 2018 10:41
-
-
Save andyman/5f5ca54392a257702239cbf210ba4839 to your computer and use it in GitHub Desktop.
AutoSaveOnPlay.cs
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(); | |
Debug.Log("Save completed."); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment