csharp Unity AutoSave - 编辑助手脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Unity AutoSave - 编辑助手脚本相关的知识,希望对你有一定的参考价值。

/// <summary>
/// AutoSave.cs, editor helper script. Saves the scene ans modified assets when you hit Play in the Unity Editor, so if Unity should 
/// crash, or similar, you don't lose any scene or assets you haddn't saved before hitting Play.
/// </summary>
/// 
/// <remarks>
/// Created (date - name): 10th March 2015 - Gavin Thornton
/// Modified (date - name): 8th Jan 2017 - Gavin Thornton - #if UNITY_EDITOR moved to fix cloud build
/// Modified (date - name): 30th March 2017 - Gavin Thornton - line "EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());" changed to multi scene version "EditorSceneManager.SaveOpenScenes();"
/// </remarks>
 
#if UNITY_EDITOR                 
using System;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

[InitializeOnLoad]

#if false                           // Change this to "#if true" if you want to disble the script temporarily (without having to delete it)
public class OnUnityLoad
{
    static OnUnityLoad()
    {
        EditorApplication.playmodeStateChanged = () =>
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
                Debug.Log("*** WARNING:Auto-Saving DISABLED ***" + EditorApplication.currentScene);
        };
    }
}

#else
public class OnUnityLoad
{
    static OnUnityLoad()
    {
        EditorApplication.playmodeStateChanged = () =>
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
            {
                // Unity 5+
                Debug.Log("Auto-saving scene and any asset edits" + EditorSceneManager.GetActiveScene());
                EditorSceneManager.SaveOpenScenes();  
                AssetDatabase.SaveAssets();
                
                // Old code for Unity 4.6 and below users below -------------------
                //Debug.Log("Auto-saving scene " + EditorApplication.currentScene);
                //EditorApplication.SaveScene();
                //EditorApplication.SaveAssets();
            }
        };
    }
}

#endif
#endif  // #if UNITY_EDITOR

以上是关于csharp Unity AutoSave - 编辑助手脚本的主要内容,如果未能解决你的问题,请参考以下文章

csharp Unity获取键盘输入

csharp Unity获取类变量

csharp [WIP] Unity Bezier

csharp unity / 2d draggable gameobject

csharp Unity系统诊断秒表

csharp Unity XcodeAPI设置示例