SaveOnPlay

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Paste the script into a file named SaveOnPlay.cs under a folder named Editor, e.g. Assets/Editor/SaveOnPlay.cs . Click play, the debug message appearing before your scene runs...")
 
m (C# - SaveOnPlay.cs: Updated for 5.3)
 
Line 21: Line 21:
 
         if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
 
         if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
 
         {
 
         {
             Debug.Log("Saving scene on play...");
+
#if UNITY_5_3
             EditorApplication.SaveScene();
+
             Debug.Log("Saving open scenes on play...");
 +
             UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
 +
#else
 +
                Debug.Log("Saving scene on play...");
 +
                EditorApplication.SaveScene();
 +
#endif
 
         }
 
         }
 
     }
 
     }

Latest revision as of 01:34, 9 December 2015

Paste the script into a file named SaveOnPlay.cs under a folder named Editor, e.g. Assets/Editor/SaveOnPlay.cs . Click play, the debug message appearing before your scene runs is a sign the save worked.

[edit] C# - SaveOnPlay.cs

using UnityEditor;
using UnityEngine;
 
[InitializeOnLoad]
public class SaveOnPlay
{
    static SaveOnPlay()
    {
        EditorApplication.playmodeStateChanged += SaveCurrentScene;
    }
 
    static void SaveCurrentScene()
    {
        if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
        {
#if UNITY_5_3
            Debug.Log("Saving open scenes on play...");
            UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
#else
                Debug.Log("Saving scene on play...");
                EditorApplication.SaveScene();
#endif
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox