Unity场景自动保存工具
2017-06-01 14:50
435 查看
Unity场景自动保存工具
难得闲下来,好好整理一下,今天主要分享一下在Unity中,开启场景的自动保存功能,是从网上买的源码中找到的,还是挺有用的,这样就算突然断电或者忘记保存了,不会导致太严重的后果,因为可以设置1-10分钟自动保存一次。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(); } }
将些脚本放置到Unity工程中的Editor文件夹中,然后点击window下的AutoSave就可以进行方便的自动保存了。
相关文章推荐
- Unity之自动保存场景
- unity 场景自动保存
- Unity编辑器扩展(自动保存当前打开的场景)
- Unity自动场景保存脚本
- Unity插件研究院之自动保存场景
- Unity插件研究院之自动保存场景
- 【转载】Unity插件研究院之自动保存场景
- Unity自动保存场景脚本
- Unity利用Xml和Json保存场景
- 可以快速保存、访问和粘贴文本片段的Unity漂亮工具
- 可以快速保存、访问和粘贴文本片段的Unity漂亮工具
- unity自动保存项目
- Unity自动打包工具——Mac上打包android
- DailyReport自动保存工具
- Unity自动打包工具
- unity 场景NPC触发漫游和间隔时间自动显示对话在人物上方的简单脚本!
- 左轮网吧IE历史QQ记录自动保存工具
- 用vbs写的自动保存小工具
- unity自动保存项目
- Unity官方教程学习笔记之Roll A Ball篇---(一)创建工程和保存场景