Unity插件研究院之自动保存场景
来源:互联网 发布:铁路货物追踪软件下载 编辑:程序博客网 时间:2024/06/06 15:24
原文: http://wiki.unity3d.com/index.php?title=AutoSave
最近发现Unity老有自动崩溃的BUG。 每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
01
using
UnityEngine;
02
using
UnityEditor;
03
using
System;
04
05
public
class
AutoSave : EditorWindow {
06
07
private
bool
autoSaveScene =
true
;
08
private
bool
showMessage =
true
;
09
private
bool
isStarted =
false
;
10
private
int
intervalScene;
11
private
DateTime lastSaveTimeScene = DateTime.Now;
12
13
private
string
projectPath = Application.dataPath;
14
private
string
scenePath;
15
16
[MenuItem (
"Window/AutoSave"
)]
17
static
void
Init () {
18
AutoSave saveWindow = (AutoSave)EditorWindow.GetWindow (
typeof
(AutoSave));
19
saveWindow.Show();
20
}
21
22
void
OnGUI () {
23
GUILayout.Label (
"Info:"
, EditorStyles.boldLabel);
24
EditorGUILayout.LabelField (
"Saving to:"
,
""
+projectPath);
25
EditorGUILayout.LabelField (
"Saving scene:"
,
""
+scenePath);
26
GUILayout.Label (
"Options:"
, EditorStyles.boldLabel);
27
autoSaveScene = EditorGUILayout.BeginToggleGroup (
"Auto save"
, autoSaveScene);
28
intervalScene = EditorGUILayout.IntSlider (
"Interval (minutes)"
, intervalScene, 1, 10);
29
if
(isStarted) {
30
EditorGUILayout.LabelField (
"Last save:"
,
""
+lastSaveTimeScene);
31
}
32
EditorGUILayout.EndToggleGroup();
33
showMessage = EditorGUILayout.BeginToggleGroup (
"Show Message"
, showMessage);
34
EditorGUILayout.EndToggleGroup ();
35
}
36
37
void
Update(){
38
scenePath = EditorApplication.currentScene;
39
if
(autoSaveScene) {
40
if
(DateTime.Now.Minute >= (lastSaveTimeScene.Minute+intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59){
41
saveScene();
42
}
43
}
else
{
44
isStarted =
false
;
45
}
46
47
}
48
49
void
saveScene() {
50
EditorApplication.SaveScene(scenePath);
51
lastSaveTimeScene = DateTime.Now;
52
isStarted =
true
;
53
if
(showMessage){
54
Debug.Log(
"AutoSave saved: "
+scenePath+
" on "
+lastSaveTimeScene);
55
}
56
AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow (
typeof
(AutoSave));
57
repaintSaveWindow.Repaint();
58
}
59
}
因为这个编辑窗口必须在激活状态,所以 你可以把它附属在某个窗口下面 比如Project视图。
为了方便你还可以把这个布局保存起来,方便下次使用。。
- Unity插件研究院之自动保存场景
- Unity插件研究院之自动保存场景
- unity 场景自动保存
- Unity插件研究院之ResourceChecker
- Unity插件研究院之ResourceChecker
- Unity插件研究院之ResourceChecker
- Unity插件研究院之ResourceChecker
- Unity插件研究院之ResourceChecker
- Unity自动保存场景脚本
- Unity场景自动保存工具
- Unity编辑器扩展(自动保存当前打开的场景)
- 【Unity插件】自动保存备份插件,极其容易失去响应
- Unity3D研究院之利用unity自带API提前合并场景Mesh
- Unity跨场景保存数据
- unity自动保存项目
- unity自动保存项目
- Unity利用Xml和Json保存场景
- Unity3D研究院之初探PoolManager插件
- .Net保存页面滚动条状态
- test
- Arcgis for javascript 学习资料
- CUDA5.5与VS2010的编译环境搭建
- 十进制,二进制,八进制,十六进制之间的转换
- Unity插件研究院之自动保存场景
- cocos2d-x 2.2.0 终端创建项目
- VC++ CTreeCtrl 中 checkbox 的使用
- 【译】样式研究:设置易读的文字
- 不安装oracle客户端也可以使用pl/sql developer
- apk签名原理及实现
- Eclipse中Server Location 设置
- 用微信玩转你的品牌-布乔
- NGUI控件改造——输入框光标可移动