Last active
June 20, 2022 03:54
-
-
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".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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