码迷,mamicode.com
首页 > 其他好文 > 详细

自动保存场景

时间:2016-01-19 12:38:32      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

 1 using UnityEngine;
 2 using UnityEditor;
 3 using System;
 4  
 5 public class AutoSave : EditorWindow {
 6  
 7     private bool autoSaveScene = true;
 8     private bool showMessage = true;
 9     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 }

 

自动保存场景

标签:

原文地址:http://www.cnblogs.com/wry524/p/5141633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!