Skip to content

Instantly share code, notes, and snippets.

@tomkail
Created May 4, 2018 10:03
Show Gist options
  • Save tomkail/ce187eb70e8c94d1b2cf73d1e9722d66 to your computer and use it in GitHub Desktop.
Save tomkail/ce187eb70e8c94d1b2cf73d1e9722d66 to your computer and use it in GitHub Desktop.
Example of how to get a callback that only runs when Unity opens (not on script recompile)
[InitializeOnLoad]
public static class OnOpenUnityEditorExample {
const string lastCompileTimeKey = "InkIntegrationLastCompileTime";
static InkEditorUtils () {
float lastCompileTime = LoadAndSaveLastCompileTime();
if(EditorApplication.timeSinceStartup < lastCompileTime)
OnOpenUnityEditor();
}
static void OnOpenUnityEditor () {
InkLibrary.Rebuild();
}
static float LoadAndSaveLastCompileTime () {
float lastCompileTime = 0;
if(EditorPrefs.HasKey(lastCompileTimeKey))
lastCompileTime = EditorPrefs.GetFloat(lastCompileTimeKey);
EditorPrefs.SetFloat(lastCompileTimeKey, (float)EditorApplication.timeSinceStartup);
return lastCompileTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment