新建一个名为AutoSave的编辑器脚本,并放于Assets/Editor下。

 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, , );
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 == && DateTime.Now.Second == )
{
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自动场景保存脚本的更多相关文章

  1. Unity脚本自动添加注释脚本及排版格式

    Unity脚本自动添加注释脚本及头部注释排版格式 公司开发项目,需要声明版权所有,,,,标注公司名,作者,时间,项目名称及描述等等. 自己总结实现的现成脚本及头部注释排版文本,添加到模版即可. 文件不 ...

  2. 【Unity】6.1 Unity中的C#脚本基础知识

    分类:Unity.C#.VS2015 创建日期:2016-04-16 一.简介 1.常用的C#数据类型 这里简单介绍用Unity开发游戏时,最常用的一些数据类型. (1)基本类型 int.float. ...

  3. Unity优化方向——优化Unity游戏中的脚本(译)

    原文地址:https://unity3d.com/cn/learn/tutorials/topics/performance-optimization/optimizing-scripts-unity ...

  4. Unity3D热更新之LuaFramework篇[07]--怎么让unity对象绑定Lua脚本

    前言 在上一篇文章 Unity3D热更新之LuaFramework篇[06]--Lua中是怎么实现脚本生命周期的 中,我分析了由LuaBehaviour来实现lua脚本生命周期的方法. 但在实际使用中 ...

  5. Entity Framework入门教程(10)---离线场景保存和删除实体/实体图集

    离线场景保存和删除实体/实体图集 这一节的内容是在离线场景中保存实体和实体图集 在离线场景中,当我们保存一个离线的实体图集或一个单独的离线实体时,我们需要做两件事.首先,我们要把实体附加到新的上下文中 ...

  6. Unity 自动生成组件索引类工具

    Unity 自动生成组件索引类工具 需求由来 我们在写UI类时 需要获取预设中的组件 joystick = transform.Find("joystick"); backgrou ...

  7. tomcat监控,自动重启shell脚本

    tomcat监控,自动重启shell脚本如下,取名 monitor_tomcat.sh: #!/bin/sh # func:自动监控tomcat脚本并且执行重启操作 # 获取tomcat进程ID(其中 ...

  8. Unity自动打包工具

    转载 https://blog.csdn.net/ynnmnm/article/details/36774715 最开始有写打包工具的想法,是因为看到<啪啪三国>王伟峰分享的一张图,他们有 ...

  9. 如何自动运行loadrunner脚本

    问题背景 在凌晨之后,自然流量比较低,无需人值守的情况自动运行loadruner脚本. 实现思路 windows定时任务+BAT脚本 BAT脚本: SET M_ROOT=C:\Program File ...

随机推荐

  1. Sort Colors [LeetCode]

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  2. zend create project prepare

    1.php ini 安装pear 设置include_path 2.apache AllowOverride LoadModule rerwite去掉注释 <VirtualHost *:> ...

  3. AFNetworking到底做了什么

    写在开头: 作为一个iOS开发,也许你不知道NSUrlRequest.不知道NSUrlConnection.也不知道NSURLSession...(说不下去了...怎么会什么都不知道...)但是你一定 ...

  4. Thinkphp 3.2.2 利用phpexcel完成excel导出功能

    首先百度搜索phpexcel  包,放到项目的这个目录下 接下来  是controller里的导出代码 /**导出预定产品用户信息 * 大白驴 675835721 *2016-12-12 **/pub ...

  5. 树(三)——自平衡二叉树(AVL)

    简介 自平衡二叉树(AVL)属于二叉平衡树的一类,此类树主要完成一个从键到值的查找过程,即字典(或映射),它维护树高度的方式与其他数据结构不同. 自平衡规则: AVL树的左.右子树都是AVL树 左.右 ...

  6. css3选择器详解

    css中除了早先最早的,ID选择器,class选择器一些以外在css3中新加入了新的选择器,新选择器的使用大大的方便了我们的编程,下面我就说一些css3的选择器的使用方法, p       选择了所有 ...

  7. 导航效果css

    <!doctype html> <html> <head> <meta charset="utf-8" /> <style&g ...

  8. ssi项目(1)环境搭建

    1.环境准备 导包(jdk1.8只支持spring4.0以上的版本) mysql驱动包 c3p0驱动包 mybatis包 spring-core.spring-aop.spring-web.sprin ...

  9. Spring 通过配置文件注入 properties文件

    当我们需要将某些值放入 properties文件 key=value 的方式,获取文件信息使用spring 注入的方式会变得很便捷 1. spring 配置文件需要导入 <?xml versio ...

  10. list内容按长度等分

    这里需要导入 from more_itertools import chunked chunked(iterable, n) 将一个可迭代对象等分成n个list,第n个list的长度可能小于之前的. ...