Created
January 20, 2018 18:33
-
-
Save ByronMayne/7a438b360e70c32596c95209c0d05a22 to your computer and use it in GitHub Desktop.
A simple method to force Unity Editor to recompile all scripts.
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
public class AssemblyUtility | |
{ | |
/// <summary> | |
/// Forces Unity to recompile all scripts and then refresh. | |
/// </summary> | |
public static void DirtyAllScripts() | |
{ | |
// Grab the UnityEditor assembly | |
Assembly editorAssembly = typeof(UnityEditor.Editor).Assembly; | |
// Find the type that contains the method we want | |
Type compilationInterface = editorAssembly.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface"); | |
// Make sure it's not null | |
if (compilationInterface != null) | |
{ | |
// Create our binding flags | |
BindingFlags staticBindingFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; | |
// Grab the dirty method | |
MethodInfo dirtyAllScriptsMethod = compilationInterface.GetMethod("DirtyAllScripts", staticBindingFlags); | |
// Invoke the static method with no arguments. | |
dirtyAllScriptsMethod.Invoke(null, null); | |
} | |
// Force the database to refresh. | |
UnityEditor.AssetDatabase.Refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment