Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Last active June 20, 2022 03:54
Show Gist options
  • Save SiarheiPilat/9b23d98e064327ac0e0023044d060e5f to your computer and use it in GitHub Desktop.
Save SiarheiPilat/9b23d98e064327ac0e0023044d060e5f to your computer and use it in GitHub Desktop.
With this, you would close Unity using a menu command instead of pressing the "close cross".
using UnityEngine;
using UnityEditor;
// TODO: rename to 'secret quit button' xD
// Maybe just have a "Sure to quit?" window?
[InitializeOnLoad]
public class AccidentalProjectClosePrevention
{
[MenuItem("Tools/Quit")]
static void AllowQuit()
{
if (UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().isDirty)
{
Debug.Log("save changes first");
return;
}
EditorPrefs.SetBool("sua_quit_allowed", true);
EditorApplication.Exit(0);
}
static bool WantsToQuit()
{
Debug.Log("Editor prevented from quitting. Quit by going Tools -> Quit");
return false;
}
static AccidentalProjectClosePrevention()
{
EditorApplication.wantsToQuit += WantsToQuit;
EditorPrefs.SetBool("sua_quit_allowed", false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment