首页 > 代码库 > unity3d 自动保存
unity3d 自动保存
using UnityEngine;using UnityEditor;using System;public class AutoSave : EditorWindow { private bool autoSaveScene = true; private bool showMessage = true; private bool isStarted = false; private int intervalScene; private DateTime lastSaveTimeScene = DateTime.Now; private string projectPath = Application.dataPath; private string scenePath; [MenuItem ("Window/AutoSave")] static void Init () { AutoSave saveWindow = (AutoSave)EditorWindow.GetWindow (typeof (AutoSave)); saveWindow.Show(); } void OnGUI () { GUILayout.Label ("Info:", EditorStyles.boldLabel); EditorGUILayout.LabelField ("Saving to:", ""+projectPath); EditorGUILayout.LabelField ("Saving scene:", ""+scenePath); GUILayout.Label ("Options:", EditorStyles.boldLabel); autoSaveScene = EditorGUILayout.BeginToggleGroup ("Auto save", autoSaveScene); intervalScene = EditorGUILayout.IntSlider ("Interval (minutes)", intervalScene, 1, 10); if(isStarted) { EditorGUILayout.LabelField ("Last save:", ""+lastSaveTimeScene); } EditorGUILayout.EndToggleGroup(); showMessage = EditorGUILayout.BeginToggleGroup ("Show Message", showMessage); EditorGUILayout.EndToggleGroup (); } void Update(){ scenePath = EditorApplication.currentScene; if(autoSaveScene) { if(DateTime.Now.Minute >= (lastSaveTimeScene.Minute+intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59){ saveScene(); } } else { isStarted = false; } } void saveScene() { EditorApplication.SaveScene(scenePath); lastSaveTimeScene = DateTime.Now; isStarted = true; if(showMessage){ Debug.Log("AutoSave saved: "+scenePath+" on "+lastSaveTimeScene); } AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow (typeof (AutoSave)); repaintSaveWindow.Repaint(); }}
因为这个编辑窗口必须在激活状态,所以 你可以把它附属在某个窗口下面 比如Project视图。
<ignore_js_op>
原地址:http://www.narkii.com/club/thread-298445-1.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。