当前位置:   article > 正文

unity 编辑器存档_Unity插件研究院之自动保存场景

unity运行时场景保存至编辑器插件

using UnityEngine;

using UnityEditor;

using System;

public class AutoSave : EditorWindow {

private bool autoSaveScene = true;

private bool showMessage = true;

private bool isStarted = false;

private int intervalScene;

private DateTime lastSaveTimeScene = DateTime.Now;

private string projectPath = Application.dataPath;

private string scenePath;

[MenuItem ("Window/AutoSave")]

static void Init () {

AutoSave saveWindow = (AutoSave)EditorWindow.GetWindow (typeof (AutoSave));

saveWindow.Show();

}

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 ();

}

void Update(){

scenePath = EditorApplication.currentScene;

if(autoSaveScene) {

if(DateTime.Now.Minute >= (lastSaveTimeScene.Minute+intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59){

saveScene();

}

} else {

isStarted = false;

}

}

void saveScene() {

EditorApplication.SaveScene(scenePath);

lastSaveTimeScene = DateTime.Now;

isStarted = true;

if(showMessage){

Debug.Log("AutoSave saved: "+scenePath+" on "+lastSaveTimeScene);

}

AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow (typeof (AutoSave));

repaintSaveWindow.Repaint();

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/141627
推荐阅读
相关标签
  

闽ICP备14008679号