zoukankan      html  css  js  c++  java
  • unity3d 自动保存

    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

  • 相关阅读:
    php 加反斜杠的原因与处理办法
    python2.7 正则表达式的学习
    关于thinkhphp3.1中废弃 preg_replace /e 修饰符
    python2.7 函数的参数学习
    Laravel中Homestead添加多站点时遇到问题
    安装pywin32时,出现找不到python27注册信息的解决办法
    递归例子
    在SUSE平台启动和关闭mysql服务
    SUSE11 安装mysql
    delphi调用dll动态库
  • 原文地址:https://www.cnblogs.com/123ing/p/3794013.html
Copyright © 2011-2022 走看看