Created
November 3, 2015 19:28
-
-
Save kinifi/2f79262d6d7b7f7e95ee to your computer and use it in GitHub Desktop.
Auto Save the current open Unity 3D level every 30 seconds
This file contains hidden or 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
/* Created by Chris Figueroa - @Kinifi | |
* Create a script called AutoSave.cs | |
*/ | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
public class AutoSave : EditorWindow { | |
private float saveTime = 30; | |
private double nextSaveTime = 0; | |
private bool stopAutoSave; | |
[MenuItem("Window/AutoSave Level")] | |
static void ShowEditor() | |
{ | |
AutoSave editor = EditorWindow.GetWindow<AutoSave>(); | |
editor.minSize = new Vector2(300, 100); | |
editor.maxSize = new Vector2(300, 100); | |
editor.Init(); | |
} | |
public void Init() | |
{ | |
Debug.Log("The level will now be saved automatically"); | |
} | |
void OnGUI() | |
{ | |
GUILayout.Label("Auto Saves Level Every 30 Seconds"); | |
stopAutoSave = GUILayout.Toggle(stopAutoSave, "Stop Auto Save"); | |
GUILayout.Space(10); | |
if (stopAutoSave == false) | |
{ | |
EditorGUILayout.LabelField("Save Each:", saveTime + " Secs"); | |
double timeToSave = nextSaveTime - EditorApplication.timeSinceStartup; | |
EditorGUILayout.LabelField("Next Save:", timeToSave.ToString() + " Sec"); | |
this.Repaint(); | |
if (EditorApplication.timeSinceStartup > nextSaveTime) | |
{ | |
var path = EditorApplication.currentScene; | |
//EditorApplication.SaveScene(path, true); | |
EditorApplication.SaveScene(); | |
EditorApplication.SaveAssets(); | |
Debug.Log("Saved Scene: " + path); | |
nextSaveTime = EditorApplication.timeSinceStartup + saveTime; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment