Skip to content

Instantly share code, notes, and snippets.

@andyman
Created September 28, 2018 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyman/5f5ca54392a257702239cbf210ba4839 to your computer and use it in GitHub Desktop.
Save andyman/5f5ca54392a257702239cbf210ba4839 to your computer and use it in GitHub Desktop.
AutoSaveOnPlay.cs
// Place inside your Editor folder inside of Assets for it to save the current scene(s) when you run.
// The folder must be called "Editor", but can be nested within something else, e.g. Scripts/Editor
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class OnUnityLoad
{
static OnUnityLoad()
{
EditorApplication.playModeStateChanged += (PlayModeStateChange change) =>
{
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
{
Debug.Log("Auto-Saving scene(s) before entering Play mode.");
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
Debug.Log("Save completed.");
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment