zoukankan      html  css  js  c++  java
  • Unity之自动保存场景

    转“Unity插件研究院之自动保存场景” 

    unity编辑器出现闪退并且刚编辑完场景没来得及保存的问题。

     1 using UnityEngine;
     2 using System.Collections;
     3 using UnityEditor;
     4 using System;
     5 
     6 public class AutoSave : EditorWindow
     7 {
     8 
     9     private bool autoSaveScene = true;
    10     private bool showMessage = true;
    11     private bool isStarted = false;
    12     private int intervalScene;
    13     private DateTime lastSaveTimeScene = DateTime.Now;
    14 
    15     private string projectPath = Application.dataPath;
    16     private string scenePath;
    17 
    18     [MenuItem("Window/AutoSave")]
    19     static void Init()
    20     {
    21         AutoSave saveWindow = (AutoSave)EditorWindow.GetWindow(typeof(AutoSave));
    22         saveWindow.Show();
    23     }
    24 
    25     void OnGUI()
    26     {
    27         GUILayout.Label("Info:", EditorStyles.boldLabel);
    28         EditorGUILayout.LabelField("Saving to:", "" + projectPath);
    29         EditorGUILayout.LabelField("Saving scene:", "" + scenePath);
    30         GUILayout.Label("Options:", EditorStyles.boldLabel);
    31         autoSaveScene = EditorGUILayout.BeginToggleGroup("Auto save", autoSaveScene);
    32         intervalScene = EditorGUILayout.IntSlider("Interval (minutes)", intervalScene, 1, 10);
    33         if (isStarted)
    34         {
    35             EditorGUILayout.LabelField("Last save:", "" + lastSaveTimeScene);
    36         }
    37         EditorGUILayout.EndToggleGroup();
    38         showMessage = EditorGUILayout.BeginToggleGroup("Show Message", showMessage);
    39         EditorGUILayout.EndToggleGroup();
    40     }
    41 
    42     void Update()
    43     {
    44         scenePath = EditorApplication.currentScene;
    45         if (autoSaveScene)
    46         {
    47             if (DateTime.Now.Minute >= (lastSaveTimeScene.Minute + intervalScene) || DateTime.Now.Minute == 59 && DateTime.Now.Second == 59)
    48             {
    49                 saveScene();
    50             }
    51         }
    52         else
    53         {
    54             isStarted = false;
    55         }
    56 
    57     }
    58 
    59     void saveScene()
    60     {
    61         EditorApplication.SaveScene(scenePath);
    62         lastSaveTimeScene = DateTime.Now;
    63         isStarted = true;
    64         if (showMessage)
    65         {
    66             Debug.Log("AutoSave saved: " + scenePath + " on " + lastSaveTimeScene);
    67         }
    68         AutoSave repaintSaveWindow = (AutoSave)EditorWindow.GetWindow(typeof(AutoSave));
    69         repaintSaveWindow.Repaint();
    70     }
    71 }

    贴上此代码,放到AssetsEditor下

    然后在unity界面的Window下寻找到AutoSave就可以啦

    然后他就会隔了时间给你保存下还提示下(提示也可以选择性的啦)

    还有在unity界面LayerOut上还可以Save Layerout.

  • 相关阅读:
    TIOBE 2011年5月编程语言排行榜:C#和ObjectiveC上升趋势不减 狼人:
    20款绝佳的HTML5应用程序示例 狼人:
    为什么开发人员不能估算时间? 狼人:
    4款基于Django框架的开源软件推荐 狼人:
    jQuery 1.6正式版发布 狼人:
    设计者更喜欢什么操作系统 狼人:
    网络结点流网络浅析 By ACReaper
    效果实现SWFUpload在JQueryUI的Dialog中无法实现上传功能
    响应中断向量美妙的微机原理2013/5/2(2)
    内存图片IOS app启动动画的实现
  • 原文地址:https://www.cnblogs.com/cathytong/p/4674188.html
Copyright © 2011-2022 走看看