收藏 分销(赏)

自动保存项目.docx

上传人:二*** 文档编号:4618343 上传时间:2024-10-07 格式:DOCX 页数:2 大小:19KB
下载 相关 举报
自动保存项目.docx_第1页
第1页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
Unity自动保存项目 Posted on 2013年06月23日 by U3d / Unity3D 基础教程/被围观 34 次 很多时候,在编写项目时,遇见Unity 的Buge导致强制退出,这时根本来不及保存hierarchy视图中的东西,这是一件很糟糕的事情,所以这篇自动保存项目场景的源码就帮你解决了这一问题。 01 using UnityEngine; 02 using UnityEditor; 03 using System; 04 05 public class AutoSave : EditorWindow 06 { 07 08 private bool autoSaveScene = true; 09 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 }//UnityD教程手册: 23 24 25 void OnGUI() 26 { 27 GUILayout.Label("Info:", EditorStyles.boldLabel); 28 EditorGUILayout.LabelField("Saving to:", "" + projectPath); 29 EditorGUILayout.LabelField("Saving scene:", "" + scenePath); 30 GUILayout.Label("Options:", EditorStyles.boldLabel); 31 autoSaveScene = EditorGUILayout.BeginToggleGroup("Auto save", autoSaveScene); 32 intervalScene = EditorGUILayout.IntSlider("Interval (minutes)", intervalScene, , ); 33 if (isStarted) 34 { 35 EditorGUILayout.LabelField("Last save:", "" + lastSaveTimeScene); 36 } 37 EditorGUILayout.EndToggleGroup(); 38 showMessage = EditorGUILayout.BeginToggleGroup("Show Message", showMessage); 39 EditorGUILayout.EndToggleGroup(); 40 } 41 42 43 void Update() 44 { 45 scenePath = EditorApplication.currentScene; 46 if (autoSaveScene) 47 { 48 if (DateTime.Now.Minute >= (lastSaveTimeScene.Minute + intervalScene) || DateTime.Now.Minute == && DateTime.Now.Second == ) 49 { 50 saveScene(); 51 } 52 } 53 else 54 { 55 isStarted = false; 56 } 57 58 } 59 //UnityD教程手册: 60 void saveScene() 61 { 62 EditorApplication.SaveScene(scenePath); 63 lastSaveTimeScene = DateTime.Now; 64 isStarted = true; 65 if (showMessage) 66 { 67 Debug.Log("AutoSave saved: " + scenePath + " on " + lastSaveTimeScene); 68 } 69 AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow(typeof(AutoSave)); 70 repaintSaveWindow.Repaint(); 71 } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 环境建筑 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服