private static void HandleAutoRefreshDisabling() { if (LiveRecompileDisablerEditorPrefs.EnableAutoRefreshAfterStopRequired) { if (!EditorApplication.isPlayingOrWillChangePlaymode) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Enabling Auto Refresh after Play Mode stop"); #endif LiveRecompileDisablerEditorPrefs.AutoRefresh = true; LiveRecompileDisablerEditorPrefs.EnableAutoRefreshAfterStopRequired = false; } } if (LiveRecompileDisablerEditorPrefs.DisableAutoRefreshInPlayMode) { if (EditorApplication.isPlayingOrWillChangePlaymode) { if (LiveRecompileDisablerEditorPrefs.AutoRefresh) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Requesting enabling Auto Refresh after Play Mode stop"); #endif LiveRecompileDisablerEditorPrefs.EnableAutoRefreshAfterStopRequired = true; LiveRecompileDisablerEditorPrefs.AutoRefresh = false; } } } }
private static void HandlePlayModeChanging() { if (LiveRecompileDisablerEditorPrefs.RestartAfterReloadingAssembliesRequired) { if (!EditorApplication.isPlayingOrWillChangePlaymode) { if (!EditorApplication.isCompiling) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Restarting after reloading assemblies"); #endif LiveRecompileDisablerEditorPrefs.RestartAfterReloadingAssembliesRequired = false; EditorApplication.isPlaying = true; } } } if (LiveRecompileDisablerEditorPrefs.ChangePlayMode) { if (EditorApplication.isPlaying) { if (EditorApplication.isCompiling) { if (!ReloadAssembliesLocked) { if (LiveRecompileDisablerEditorPrefs.PlayMode == LiveRecompileDisablerPlayMode.Pause) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Pausing Play Mode on compilation"); #endif EditorApplication.isPaused = true; } else if ((LiveRecompileDisablerEditorPrefs.PlayMode & LiveRecompileDisablerPlayMode.Stop) == LiveRecompileDisablerPlayMode.Stop) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Stoping Play Mode on compilation"); #endif EditorApplication.isPlaying = false; EditorApplication.isPaused = false; LiveRecompileDisablerEditorPrefs.RestartAfterReloadingAssembliesRequired = (LiveRecompileDisablerEditorPrefs.PlayMode == LiveRecompileDisablerPlayMode.Restart); if (LiveRecompileDisablerEditorPrefs.RestartAfterReloadingAssembliesRequired) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Restarting after reloading assemblies requested"); #endif } } } } } } }
private static void OnEditorApplicationGlobalEvent() { var e = Event.current; if (!e.isKey) { return; } #if LOG_LRD_KEY_EVENTS var logType = e.type.ToString().Replace("Key", string.Empty).ToLower(); var logModifiers = e.modifiers.ToString().Replace(", ", "+"); var logKey = e.keyCode.ToString(); var logHotKeyFormat = (e.control) ? "{1}" : (e.control) ? "{1}+{0}" : "{0}"; LiveRecompileDisablerLogger.Log(string.Format("Key {0} {1}", logType, string.Format(logHotKeyFormat, logKey, logModifiers))); #endif // Most times Control+R will not be triggered because it is Unity editor hot key, but key up events triggered as usual. if (!e.control && !previousControl) { return; } previousControl = (e.control || e.keyCode == KeyCode.LeftControl); if (e.alt) { return; } if (e.shift) { return; } if (e.command) { return; } if (e.keyCode != KeyCode.R) { return; } #if LOG_LRD LiveRecompileDisablerLogger.Log("Manual refresh requested (Control+R pressed)"); #endif if (ReloadRequested != null) { ReloadRequested(); } }
private static void LockReloadAssemblies() { if (ReloadAssembliesLocked) { return; } ReloadAssembliesLocked = true; #if LOG_LRD LiveRecompileDisablerLogger.Log("Reloading assemblies locked"); #endif EditorApplication.LockReloadAssemblies(); }
private static void UnlockReloadAssemblies() { if (!ReloadAssembliesLocked) { return; } ReloadAssembliesLocked = false; #if LOG_LRD LiveRecompileDisablerLogger.Log("Reloading assemblies unlocked"); #endif EditorApplication.UnlockReloadAssemblies(); if (EditorApplication.isCompiling) { DisableTemporaryReloadAssembliesLocking = true; } }
private static void HandleAssembliesReloading() { if (LiveRecompileDisablerEditorPrefs.ReloadAssembliesAfterStopRequired) { if (!EditorApplication.isPlayingOrWillChangePlaymode) { LiveRecompileDisablerEditorPrefs.ReloadAssembliesAfterStopRequired = false; if (ReloadAssembliesLocked) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Reloading assemblies after Play Mode stop"); #endif UnlockReloadAssemblies(); } } } // Before Playing we should reload assemblies any way. if (ReloadAssembliesLocked) { if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) { UnlockReloadAssemblies(); } } if (DisableTemporaryReloadAssembliesLocking) { if (!EditorApplication.isCompiling) { DisableTemporaryReloadAssembliesLocking = false; } else { return; } } var reloadAssembliesInCurrentMode = (EditorApplication.isPlayingOrWillChangePlaymode) ? LiveRecompileDisablerEditorPrefs.ReloadAssembliesInPlayMode : (LiveRecompileDisablerReloadAssembliesInPlayMode) LiveRecompileDisablerEditorPrefs.ReloadAssembliesInEditMode; if (reloadAssembliesInCurrentMode == LiveRecompileDisablerReloadAssembliesInPlayMode.Automatical) { if (ReloadAssembliesLocked) { UnlockReloadAssemblies(); } } else { if (EditorApplication.isCompiling && LiveRecompileDisablerEditorPrefs.AutoRefresh && !ReloadAssembliesLocked) { LockReloadAssemblies(); // Reloading assemblies after Play Mode stop. if (reloadAssembliesInCurrentMode == LiveRecompileDisablerReloadAssembliesInPlayMode.AutomaticalAfterStop) { if (EditorApplication.isPlayingOrWillChangePlaymode) { #if LOG_LRD LiveRecompileDisablerLogger.Log("Requesting reloading assemblies after Play Mode stop"); #endif LiveRecompileDisablerEditorPrefs.ReloadAssembliesAfterStopRequired = true; } } } } }