Created
February 15, 2021 21:21
-
-
Save James-Frowen/6b8d92e10df2488d903950db6e5780a2 to your computer and use it in GitHub Desktop.
Exits play more when scripts are recompiled
This file contains 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 UnityEditor; | |
using UnityEditor.Compilation; | |
using UnityEngine; | |
namespace JamesFrowen.EditorScripts.Compilation | |
{ | |
/// <summary> | |
/// Stop the game the scripts are recomplied | |
/// </summary> | |
[InitializeOnLoad] | |
public static class ExitPlayModeOnCompile | |
{ | |
static ExitPlayModeOnCompile() | |
{ | |
#if UNITY_2019_1_OR_NEWER | |
CompilationPipeline.compilationStarted += CompilationPipeline_compilationStarted; | |
#else | |
CompilationPipeline.assemblyCompilationStarted += CompilationPipeline_compilationStarted; | |
#endif | |
} | |
/// <summary> | |
/// Stop playing before compile, this is useful for scripts that dont behave well with reloading | |
/// </summary> | |
/// <param name="obj"></param> | |
private static void CompilationPipeline_compilationStarted(object obj) | |
{ | |
if (Application.isPlaying) | |
{ | |
EditorApplication.isPlaying = false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment