Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- #if UNITY_5_3_OR_NEWER
- using UnityEditor.SceneManagement;
- #endif
- using UnityEngine;
- internal class AutosaveUnity {
- private static bool autosaveEnabled {
- get { return EditorPrefs.GetBool("Autosave", true); }
- set { EditorPrefs.SetBool("Autosave", value); }
- }
- [MenuItem("Edit/Autosave", false, -10000000)]
- private static void AutosaveMenu() {
- autosaveEnabled = !autosaveEnabled;
- Menu.SetChecked("Edit/Autosave", autosaveEnabled);
- }
- [MenuItem("Edit/Autosave", true, -10000000)]
- private static bool MenuCheck() {
- Menu.SetChecked("Edit/Autosave", autosaveEnabled);
- return true;
- }
- [InitializeOnLoadMethod]
- private static void Init() {
- EditorApplication.playmodeStateChanged += () => {
- if(EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) {
- if(autosaveEnabled) {
- Debug.Log("Auto-Saving project");
- #if UNITY_5_3_OR_NEWER
- EditorSceneManager.SaveOpenScenes();
- #else
- EditorApplication.SaveScene();
- #endif
- AssetDatabase.SaveAssets();
- }
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement