Unity插件研究院之自动保存场景
2016-02-19 23:19
567 查看
原文: http://wiki.unity3d.com/index.php?title=AutoSave
最近发现Unity老有自动崩溃的BUG。 每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
C#
因为这个编辑窗口必须在激活状态,所以 你可以把它附属在某个窗口下面 比如Project视图。
![](http://www.xuanyusong.com/wp-content/uploads/2013/05/2_320_a155bad1a281d9f.png)
为了方便你还可以把这个布局保存起来,方便下次使用。。
![](http://www.xuanyusong.com/wp-content/uploads/2013/05/2_320_53108826434864f.png)
最近发现Unity老有自动崩溃的BUG。 每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 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(); } } |
![](http://www.xuanyusong.com/wp-content/uploads/2013/05/2_320_a155bad1a281d9f.png)
为了方便你还可以把这个布局保存起来,方便下次使用。。
![](http://www.xuanyusong.com/wp-content/uploads/2013/05/2_320_53108826434864f.png)
相关文章推荐
- Unity3D热更新 -脚本(三) C#LightEvil语法与调试
- Unity3D热更新 -脚本(二) 两级分化
- Unity3D热更新 初识脚本
- Unity3D逻辑热更新,第二代舒爽解决方案,L#使用简介
- Unity3D热更新 下载
- Unity3d热更新 加载(二)如何在不用AssetBundle的前提下动态加载预设
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(56)-插件---单文件上传与easyui使用fancybox
- Unity3d热更新 从AssetBundle说起
- unity 优化
- 在顶点照明模式下如何取得光源信息
- Unity3d 编写编辑器自定义插件(1)
- Unity Physics.Raycast 之 layerMask
- Unity dll 热更新 基础框架
- 《VR入门系列教程》之14---面向大众的Unity3D
- Unity3D面试题整合
- 在unity里绘图板 制作一个画板的几种思路和原理
- Unity 武器拖尾效果插件Pocket RPG Weapon Trails
- Unity3D Android 开发环境配置
- unity3d中UIToggle相关组件的使用
- unity 内存优化