Last active
March 24, 2021 10:05
-
-
Save Marsgames/40635c471ea962dd55a7afac5348c385 to your computer and use it in GitHub Desktop.
Put it in Assets/Editor. Automaticaly save scene every time you press 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
using UnityEditor; | |
using UnityEngine; | |
using UnityEditor.SceneManagement; | |
[InitializeOnLoad, HelpURL("https://forum.unity.com/threads/we-need-auto-save-feature.483853")] | |
public static class AutoSave | |
{ | |
/// <summary> | |
/// Static constructor that gets called when unity fires up. | |
/// </summary> | |
static AutoSave() | |
{ | |
EditorApplication.playModeStateChanged += (PlayModeStateChange state) => | |
{ | |
// If we're about to run the scene... | |
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) | |
{ | |
// Save the scene and the assets. | |
Debug.Log("Auto-saving all open scenes... " + state); | |
EditorSceneManager.SaveOpenScenes(); | |
AssetDatabase.SaveAssets(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment