SaveOnPlay

From Unify Community Wiki
Revision as of 09:40, 26 September 2015 by Irwiss (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.

C# - SaveOnPlay.cs

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

Variants
Actions
Navigation
Extras
Toolbox