1 自动保存场景脚本,是一个js脚本,放到Editor文件夹下,在任务栏的Window下就可以看到SimpleSave了,点击后会打开一个小窗口,这个窗口必须一直存在前台,关闭就会停止.
saveTime : 是30秒保存一次
- import UnityEditor;
-
- class SimpleAutoSave extends EditorWindow {
-
- var saveTime : float = 30;
- var nextSave : float = 0;
-
- @MenuItem("Window/SimpleSave")
- static function Init() {
- var window : SimpleAutoSave =
- EditorWindow.GetWindowWithRect(
- SimpleAutoSave,
- Rect(0,0,165,40));
- window.Show();
- }
-
- function OnEnable(){
- nextSave = EditorApplication.timeSinceStartup + saveTime;
- }
-
- function OnGUI() {
- EditorGUILayout.LabelField("Save Each:", saveTime + " Secs");
- var timeToSave : int = nextSave - EditorApplication.timeSinceStartup;
- EditorGUILayout.LabelField("Next Save:", timeToSave.ToString() + " Sec");
- this.Repaint();
-
- if(EditorApplication.timeSinceStartup > nextSave) {
- var path = EditorApplication.currentScene;
- try{
- EditorApplication.SaveScene(path);
- }
- catch(error){
- }
-
- nextSave = EditorApplication.timeSinceStartup + saveTime;
- }
- }
- }
- 复制代码