Unity自动场景保存脚本
2016-07-05 21:40
405 查看
新建一个名为AutoSave的编辑器脚本,并放于Assets/Editor下。
在Window/AutoSave可以打开该面板,该脚本将自动识别项目路径并定时保存场景。
using System; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; public class AutoSave : EditorWindow { private bool _autoSaveScene; private bool _showMessage; private bool _isStarted; private int _intervalScene; private DateTime _lastSaveTimeScene = DateTime.Now; private readonly string _projectPath = Application.dataPath; private string _scenePath; [MenuItem("Window/AutoSave")] private static void Init() { AutoSave saveWindow = (AutoSave) GetWindow(typeof (AutoSave)); saveWindow.Show(); } private void OnGUI() { GUILayout.Label("Info:", EditorStyles.boldLabel); EditorGUILayout.LabelField("Saving to:", "" + _projectPath); EditorGUILayout.LabelField("Saving scene:", "" + _scenePath); GUILayout.Label("Options:", EditorStyles.boldLabel); _autoSaveScene = EditorGUILayout.BeginToggleGroup("Auto save", _autoSaveScene); _intervalScene = EditorGUILayout.IntSlider("Interval (minutes)", _intervalScene, 1, 10); if (_isStarted) { EditorGUILayout.LabelField("Last save:", "" + _lastSaveTimeScene); } EditorGUILayout.EndToggleGroup(); _showMessage = EditorGUILayout.BeginToggleGroup("Show Message", _showMessage); EditorGUILayout.EndToggleGroup(); } private void Update() { _scenePath = SceneManager.GetActiveScene().path; if (_autoSaveScene) { if (DateTime.Now.Minute >= (_lastSaveTimeScene.Minute + _intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59) { SaveScene(); } } else { _isStarted = false; } } private void SaveScene() { EditorSceneManager.SaveScene(SceneManager.GetActiveScene()); _lastSaveTimeScene = DateTime.Now; _isStarted = true; if (_showMessage) { Debug.Log("AutoSave saved: " + _scenePath + " on " + _lastSaveTimeScene); } AutoSave repaintSaveWindow = (AutoSave) GetWindow(typeof (AutoSave)); repaintSaveWindow.Repaint(); } }
在Window/AutoSave可以打开该面板,该脚本将自动识别项目路径并定时保存场景。
相关文章推荐
- Unity头戴式游戏制作视频教程
- 【转】Unity3d + NGUI 的多分辨率适配
- 【Unity Shader】自定义材质面板的小技巧
- Unity中的优化技术
- Unity3D LOD Group
- 如何用Unity和Cardboard做一款VR游戏
- Unity局部高效实时阴影的思考和实现
- Unity Shader Example 8 (光照贴图)
- 5.Lambert光照Diffuse Shader
- Unity3D手游开发日记(9) - 互动草的效果
- Unity5.2.3p3破解方法
- Unity GUI(uGUI)使用心得与性能总结
- Unity插件 - MeshEditor(四) 模型融化特效
- Unity插件 - MeshEditor(四) 模型融化特效
- unity3d小常识
- HoloLens开发手记 - Unity之场景共享 Shared holographic experiences in Unity
- Unity3D 使用Mecanim实现连击
- unity自制延迟定时回调
- UnityRPG系列笔记----3
- Uniyt热更新——LuaFrameWork学习(三)判断unity里对象为空