Created
May 4, 2018 10:03
-
-
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)
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
| [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