【转载】Unity插件研究院之自动保存场景
2014-10-16 08:20
447 查看
原文: http://wiki.unity3d.com/index.php?title=AutoSave
最近发现Unity老有自动崩溃的BUG。 每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
因为这个编辑窗口必须在激活状态,所以 你可以把它附属在某个窗口下面 比如Project视图。
为了方便你还可以把这个布局保存起来,方便下次使用。。
本文固定链接: http://www.xuanyusong.com/archives/2309
转载请注明: 雨松MOMO 2013年05月08日 于 雨松MOMO程序研究院 发表
最近发现Unity老有自动崩溃的BUG。 每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
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视图。
为了方便你还可以把这个布局保存起来,方便下次使用。。
本文固定链接: http://www.xuanyusong.com/archives/2309
转载请注明: 雨松MOMO 2013年05月08日 于 雨松MOMO程序研究院 发表
相关文章推荐
- Unity插件研究院之自动保存场景
- Unity插件研究院之自动保存场景
- Unity自动保存场景脚本
- Unity之自动保存场景
- unity 场景自动保存
- Unity场景自动保存工具
- 【Unity插件】自动保存备份插件,极其容易失去响应
- Unity自动场景保存脚本
- Unity编辑器扩展(自动保存当前打开的场景)
- 【转载】Unity3d UnityEditor编辑器定制和开发插件
- VisualStudio自动编码插件(Autocode——devprojects.net)(转载)
- WordPress 删除自动保存修订版和草稿插件 WP Cleaner
- Unity插件 暂停场景中的游戏对象
- Unity 3D自动保存项目
- wordpress禁止文章修订和自动保存的方法(非插件,免修改源码)
- 【转载】插件自动升级
- [转载]Grunt插件之LiveReload 实现页面自动刷新,所见即所得编辑
- Unity插件研究院之ResourceChecker
- 使用Outlook插件实现自动保存邮件为TestTrack记录
- unity自动保存项目