欢迎来到天天文库
浏览记录
ID:59357620
大小:63.99 KB
页数:6页
时间:2020-09-04
《如何让Unity自动保存场景.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、学IT技能上我学院网woxueyuan.com如何让Unity自动保存场景?我们在Unity开发过程中会发现总是会有自动崩溃的bug,而且每次崩溃可能因为没有保存项目,所以Hierarchy视图游戏对象与相关游戏资源会丢失,这个时候你就需要通过自动保存来保证你的项目进度不会丢失了。如何在Untiy中实现自动保存场景呢,我们来看一下教程。usingUnityEngine;usingUnityEditor;usingSystem;publicclassAutoSave:EditorWindow{privateboolautoSaveScene=true;
2、privateboolshowMessage=true;privateboolisStarted=false;privateintintervalScene;privateDateTimelastSaveTimeScene=DateTime.Now;privatestringprojectPath=Application.dataPath;privatestringscenePath;Unity3D
3、Cocos
4、php
5、HTML5
6、Java
7、ios
8、Android
9、C#
10、AS3
11、UI设计
12、原画设计
13、动漫美术
14、游戏策划学IT技能上我学院网woxueyu
15、an.com[MenuItem("Window/AutoSave")]staticvoidInit(){AutoSavesaveWindow=(AutoSave)EditorWindow.GetWindow(typeof(AutoSave));saveWindow.Show();}voidOnGUI(){GUILayout.Label("Info:",EditorStyles.boldLabel);EditorGUILayout.LabelField("Savingto:",""+projectPath);EditorGUILayout.LabelF
16、ield("Savingscene:",""+scenePath);GUILayout.Label("Options:",EditorStyles.boldLabel);autoSaveScene=EditorGUILayout.BeginToggleGroup("Autosave",autoSaveScene);intervalScene=EditorGUILayout.IntSlider("Interval(minutes)",intervalScene,1,10);if(isStarted){EditorGUILayout.LabelField
17、("Lastsave:",""+lastSaveTimeScene);Unity3D
18、Cocos
19、php
20、HTML5
21、Java
22、ios
23、Android
24、C#
25、AS3
26、UI设计
27、原画设计
28、动漫美术
29、游戏策划学IT技能上我学院网woxueyuan.com}EditorGUILayout.EndToggleGroup();showMessage=EditorGUILayout.BeginToggleGroup("ShowMessage",showMessage);EditorGUILayout.EndToggleGroup();}voidUpdate(){
30、scenePath=EditorApplication.currentScene;if(autoSaveScene){if(DateTime.Now.Minute>=(lastSaveTimeScene.Minute+intervalScene)
31、
32、DateTime.Now.Minute==59&&DateTime.Now.Second==59){saveScene();}}else{isStarted=false;}Unity3D
33、Cocos
34、php
35、HTML5
36、Java
37、ios
38、Android
39、C#
40、AS3
41、UI设计
42、原画设计
43、动漫美术
44、游戏策划
45、学IT技能上我学院网woxueyuan.com}voidsaveScene(){EditorApplication.SaveScene(scenePath);lastSaveTimeScene=DateTime.Now;isStarted=true;if(showMessage){Debug.Log("AutoSavesaved:"+scenePath+"on"+lastSaveTimeScene);}AutoSaverepaintSaveWindow=(AutoSave)EditorWindow.GetWindow(typeof(AutoSave)
46、);repaintSaveWindow.Repaint();}}因为这个编辑窗口必须在激活状态,所以你可以把
此文档下载收益归作者所有