unity 编辑器存档_Unity自动保存项目

很多时候,在编写项目时,遇见Unity 的Buge导致强制退出,这时根本来不及保存hierarchy视图中的东西,

这是一件很糟糕的事情,所以这篇自动保存项目场景的源码就帮你解决了这一问题。

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

}//UnityD教程手册:www.unitymanual.com

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

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 ==  && DateTime.Now.Second == )

{

saveScene();

}

}

else

{

isStarted = false;

}

}

//UnityD教程手册:www.unitymanual.com

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

}

}

复制代码测试下哟。。。

记得留下你的 意见哟。。。

(责任编辑:脚印)

免责声明:Unity之家部分内容来源于互联网,如有侵权,请联系我们,本站将立即进行处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值