博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity3d 自动保存
阅读量:7026 次
发布时间:2019-06-28

本文共 2096 字,大约阅读时间需要 6 分钟。

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

 因为这个编辑窗口必须在激活状态,所以 你可以把它附属在某个窗口下面 比如Project视图。

<ignore_js_op>jjj.png 

 

原地址:http://www.narkii.com/club/thread-298445-1.html

转载地址:http://pisxl.baihongyu.com/

你可能感兴趣的文章
OSChina 周六乱弹 ——白天写代码,晚上跑滴滴,都是有故事的男同学
查看>>
OSChina 周日乱弹 ——程序员女友爆照!404
查看>>
swift3.0 dispatch_after 延时操作
查看>>
NGUI v301 官网详解 Example 3 - Menu
查看>>
抽象工厂模式——创建型模式
查看>>
网页检测摇一摇
查看>>
2013-9-11
查看>>
使用 Jersey 和 Apache Tomcat 7 构建 JAX-RS 环境
查看>>
正则的部分表达式(转载)
查看>>
hql查询
查看>>
模仿酷狗7(Kugou7)音乐魔方界面源码
查看>>
剑指offer之字符串是否为数值
查看>>
我的友情链接
查看>>
HTTP Cookie 详解
查看>>
Lab4-CUCM PUB First Configuration
查看>>
关于MS12-020 3389 0day exp 远程桌面执行代码漏洞的文章
查看>>
既然入了IT这行得不停的学习,不进则退
查看>>
本地项目上传到github
查看>>
调试Angular代码的Batarang插件不能用的问题
查看>>
文件测试
查看>>