Last active
January 11, 2016 18:11
-
-
Save rmalecki/c2f2dec0a040e8681dc1 to your computer and use it in GitHub Desktop.
Unity Editor Autosave
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 UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
[InitializeOnLoad] | |
public class AutoSave : ScriptableWizard | |
{ | |
private static float autoSaveDelay = 15.0f; | |
private static double timeSinceAutoSave; | |
private static bool sEnabled; | |
public float delay = autoSaveDelay; | |
public bool enabled = sEnabled; | |
[MenuItem ("File/Autosave..")] | |
static void OpenWizard () { | |
ScriptableWizard.DisplayWizard<AutoSave>("Autosave", "Apply"); | |
} | |
void OnWizardCreate () { | |
sEnabled = enabled; | |
autoSaveDelay = delay; | |
Debug.Log("Autosaving " + (enabled ? "enabled." : "disabled.")); | |
} | |
static AutoSave() { | |
EditorApplication.update += Update; | |
timeSinceAutoSave = EditorApplication.timeSinceStartup; | |
} | |
static void Update () | |
{ | |
var now = EditorApplication.timeSinceStartup; | |
if (sEnabled && now > timeSinceAutoSave + autoSaveDelay) { | |
Debug.Log("Autosaving.."); | |
EditorApplication.SaveAssets(); | |
EditorSceneManager.SaveOpenScenes(); | |
timeSinceAutoSave = now; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment