Skip to content

Instantly share code, notes, and snippets.

@andykorth
Created March 15, 2018 19:25
Show Gist options
  • Save andykorth/13b9b314c4d82e949ce26a6e66e15f39 to your computer and use it in GitHub Desktop.
Save andykorth/13b9b314c4d82e949ce26a6e66e15f39 to your computer and use it in GitHub Desktop.
using System;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class EditorApplicationCompilationUtil {
static EditorApplicationCompilationUtil() {
EditorApplication.update += EditorApplicationCompilationUtil.OnEditorUpdate;
}
private static bool StoredCompilingState {
get { return EditorPrefs.GetBool("EditorApplicationCompilationUtil::StoredCompilingState"); }
set { EditorPrefs.SetBool("EditorApplicationCompilationUtil::StoredCompilingState", value); }
}
private static void OnEditorUpdate() {
if (EditorApplication.isCompiling && EditorApplicationCompilationUtil.StoredCompilingState == false) {
EditorApplicationCompilationUtil.StoredCompilingState = true;
EditorPrefs.SetString("compileTimeStart", "" + (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
}
if (!EditorApplication.isCompiling && EditorApplicationCompilationUtil.StoredCompilingState == true) {
EditorApplicationCompilationUtil.StoredCompilingState = false;
AssetDatabase.SaveAssets();
long startCompile = long.Parse(EditorPrefs.GetString("compileTimeStart", "0"));
Debug.Log("Compile time: " + (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - startCompile) + " ms.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment