unity 场景自动保存
2014-01-31 19:10
495 查看
最近发现Unity老有自动崩溃的BUG。每次崩溃的时候由于项目没有保存所以Hierarchy视图游戏对象与游戏资源的关系就会丢失。所以想到自动保存场景。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
因为这个编辑窗口必须在激活状态,所以你可以把它附属在某个窗口下面比如Project视图。
为了方便你还可以把这个布局保存起来,方便下次使用。。
本来想自己写一个这样的脚本,但是发现维基百科上已经有了。。。
usingUnityEngine;
usingUnityEditor;
usingSystem;
publicclassAutoSave:EditorWindow{
privateboolautoSaveScene=
true
;
privateboolshowMessage=
true
;
privateboolisStarted=
false
;
privateintintervalScene;
privateDateTimelastSaveTimeScene=DateTime.Now;
privatestringprojectPath=Application.dataPath;
privatestringscenePath;
[MenuItem(
"Window/AutoSave"
)]
staticvoidInit(){
AutoSavesaveWindow=(AutoSave)EditorWindow.GetWindow(
typeof
(AutoSave));
saveWindow.Show();
}
voidOnGUI(){
GUILayout.Label(
"Info:"
,
EditorStyles.boldLabel);
EditorGUILayout.LabelField(
"Savingto:"
,
""
+projectPath);
EditorGUILayout.LabelField(
"Savingscene:"
,
""
+scenePath);
GUILayout.Label(
"Options:"
,
EditorStyles.boldLabel);
autoSaveScene=EditorGUILayout.BeginToggleGroup(
"Auto
save"
,autoSaveScene);
intervalScene=EditorGUILayout.IntSlider(
"Interval
(minutes)"
,intervalScene,1,10);
if
(isStarted){
EditorGUILayout.LabelField(
"Lastsave:"
,
""
+lastSaveTimeScene);
}
EditorGUILayout.EndToggleGroup();
showMessage=EditorGUILayout.BeginToggleGroup(
"Show
Message"
,showMessage);
EditorGUILayout.EndToggleGroup();
}
voidUpdate(){
scenePath=EditorApplication.currentScene;
if
(autoSaveScene){
if
(DateTime.Now.Minute>=(lastSaveTimeScene.Minute+intervalScene)
||DateTime.Now.Minute==59&&DateTime.Now.Second==59){
saveScene();
}
}
else
{
isStarted=
false
;
}
}
voidsaveScene(){
EditorApplication.SaveScene(scenePath);
lastSaveTimeScene=DateTime.Now;
isStarted=
true
;
if
(showMessage){
Debug.Log(
"AutoSavesaved:"
+scenePath+
"
on"
+lastSaveTimeScene);
}
AutoSaverepaintSaveWindow=(AutoSave)EditorWindow.GetWindow(
typeof
(AutoSave));
repaintSaveWindow.Repaint();
}
}
因为这个编辑窗口必须在激活状态,所以你可以把它附属在某个窗口下面比如Project视图。
为了方便你还可以把这个布局保存起来,方便下次使用。。
相关文章推荐
- Unity自动保存场景脚本
- Unity自动场景保存脚本
- Unity插件研究院之自动保存场景
- 【转载】Unity插件研究院之自动保存场景
- Unity场景自动保存工具
- Unity插件研究院之自动保存场景
- Unity编辑器扩展(自动保存当前打开的场景)
- Unity之自动保存场景
- unity 场景NPC触发漫游和间隔时间自动显示对话在人物上方的简单脚本!
- Unity利用Xml和Json保存场景
- Unity死机未保存场景怎么办
- unity自动保存项目
- Unity 场景保存,上传服务器,在下载更新场景 IO读取图片和WWW读取图片比较
- Unity官方教程学习笔记之Roll A Ball篇---(一)创建工程和保存场景
- Unity18--鼠标和场景相反运动、物体绕过障碍物,向目标自动移动,且鼠标点击哪里,物体也运动
- 关于unity中使用Vuforia制作AR场景如何设置自动对焦的问题(全网独家)
- unity自动保存项目
- 【Unity插件】自动保存备份插件,极其容易失去响应
- unity自动保存项目
- Unity跨场景保存数据