unity自动保存项目
来源:互联网 发布:后缀表达式c语言算法 编辑:程序博客网 时间:2024/06/10 20:25
很多时候,在编写项目时,遇见unity 的Buge导致强制退出,这时根本来不及保存hierarchy视图中的东西,这是一件很糟糕的事情,所以在今天看资料时,有幸的看到了这篇自动保存项目场景的源码。很是不错。
源码如下:
1 using UnityEngine; 2 using UnityEditor; 3 using System; 4 5 public class AutoSave : EditorWindow 6 { 7 8 private bool autoSaveScene = true; 9 private bool showMessage = true;10 private bool isStarted = false;11 private int intervalScene;12 private DateTime lastSaveTimeScene = DateTime.Now;13 14 private string projectPath = Application.dataPath;15 private string scenePath;16 17 [MenuItem("Window/AutoSave")]18 static void Init()19 {20 AutoSave saveWindow = (AutoSave)EditorWindow.GetWindow(typeof(AutoSave));21 saveWindow.Show();22 }23 24 void OnGUI()25 {26 GUILayout.Label("Info:", EditorStyles.boldLabel);27 EditorGUILayout.LabelField("Saving to:", "" + projectPath);28 EditorGUILayout.LabelField("Saving scene:", "" + scenePath);29 GUILayout.Label("Options:", EditorStyles.boldLabel);30 autoSaveScene = EditorGUILayout.BeginToggleGroup("Auto save", autoSaveScene);31 intervalScene = EditorGUILayout.IntSlider("Interval (minutes)", intervalScene, 1, 10);32 if (isStarted)33 {34 EditorGUILayout.LabelField("Last save:", "" + lastSaveTimeScene);35 }36 EditorGUILayout.EndToggleGroup();37 showMessage = EditorGUILayout.BeginToggleGroup("Show Message", showMessage);38 EditorGUILayout.EndToggleGroup();39 }40 41 42 void Update()43 {44 scenePath = EditorApplication.currentScene;45 if (autoSaveScene)46 {47 if (DateTime.Now.Minute >= (lastSaveTimeScene.Minute + intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59)48 {49 saveScene();50 }51 }52 else53 {54 isStarted = false;55 }56 57 }58 59 void saveScene()60 {61 EditorApplication.SaveScene(scenePath);62 lastSaveTimeScene = DateTime.Now;63 isStarted = true;64 if (showMessage)65 {66 Debug.Log("AutoSave saved: " + scenePath + " on " + lastSaveTimeScene);67 }68 AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow(typeof(AutoSave));69 repaintSaveWindow.Repaint();70 }71 }
值得注意的是:创建好这个脚本后,放在Assets/Editor文件夹中,然后编辑的窗口再Window目录下。
在激活状态下,才可有效。希望对大家有所帮助。
原文来自于:http://wiki.unity3d.com/index.php?title=AutoSave#C.23_-_AutoSave.cs (奋斗的菜鸟_1029633680)
- unity自动保存项目
- unity自动保存项目
- Unity 3D自动保存项目
- unity 场景自动保存
- Unity自动保存场景脚本
- Unity场景自动保存工具
- Unity插件研究院之自动保存场景
- Unity插件研究院之自动保存场景
- Unity 自动导出 AndroidStudio 项目
- 【Unity插件】自动保存备份插件,极其容易失去响应
- Unity编辑器扩展(自动保存当前打开的场景)
- webstorm 打开多个项目,自动保存
- unity编译时自动结束项目运行
- 自动保存
- 用Myeclipse保存时自动编译!不用重新加载项目
- vs2008 怎么设置创建项目时不要自动保存解决方案
- SharePoint 2013 新建项目字段自动加载上次保存值
- 项目中当页面修改时自动保存到日志
- java实现二维码生成的几个方法
- oracle编写过程以及存储过程在java中的调用
- 关于数组的几道面试题
- C程序设计课程 第十一次实验任务
- mysql ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.s
- unity自动保存项目
- win7系统中的Powershell命令
- 菜鸟入门项目的心路历程
- Java内存分配、管理小结
- 有用网址
- Win8 传感器,GPS, 异步操作, 读写文件
- Tales of Mystery and Imagination——3、 The Masque of the Red Death
- IE下判断IE版本的语句
- unity中连线