From 6085dbf705302692ded04e7e1d6d312162235a47 Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 9 Nov 2020 10:17:09 -0600 Subject: [PATCH] add disable script reload this script is simply a mild improvement over autorefresh. it disables autorefresh only when the app starts running, but not when it isn't running --- Paths/Assets/Editor.meta | 8 +++++ Paths/Assets/Editor/DisableScriptReload.cs | 33 +++++++++++++++++++ .../Assets/Editor/DisableScriptReload.cs.meta | 3 ++ 3 files changed, 44 insertions(+) create mode 100644 Paths/Assets/Editor.meta create mode 100644 Paths/Assets/Editor/DisableScriptReload.cs create mode 100644 Paths/Assets/Editor/DisableScriptReload.cs.meta diff --git a/Paths/Assets/Editor.meta b/Paths/Assets/Editor.meta new file mode 100644 index 0000000..350cc08 --- /dev/null +++ b/Paths/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e68c512255cf4b718b81a87be7296a76 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Paths/Assets/Editor/DisableScriptReload.cs b/Paths/Assets/Editor/DisableScriptReload.cs new file mode 100644 index 0000000..d0de55d --- /dev/null +++ b/Paths/Assets/Editor/DisableScriptReload.cs @@ -0,0 +1,33 @@ +using UnityEditor; +using UnityEngine; + +/// +/// Prevents script compilation and reload while in play mode. +/// The editor will show a the spinning reload icon if there are unapplied changes but will not actually +/// apply them until playmode is exited. +/// Note: Script compile errors will not be shown while in play mode. +/// Derived from the instructions here: +/// https://support.unity3d.com/hc/en-us/articles/210452343-How-to-stop-automatic-assembly-compilation-from-script +/// +[InitializeOnLoad] +public class DisableScriptReload { + static DisableScriptReload() { + EditorApplication.playModeStateChanged + += OnPlayModeStateChanged; + } + + static void OnPlayModeStateChanged(PlayModeStateChange stateChange) { + switch (stateChange) { + case (PlayModeStateChange.EnteredPlayMode): { + EditorApplication.LockReloadAssemblies(); + Debug.Log("Assembly Reload locked as entering play mode"); + break; + } + case (PlayModeStateChange.ExitingPlayMode): { + Debug.Log("Assembly Reload unlocked as exiting play mode"); + EditorApplication.UnlockReloadAssemblies(); + break; + } + } + } +} \ No newline at end of file diff --git a/Paths/Assets/Editor/DisableScriptReload.cs.meta b/Paths/Assets/Editor/DisableScriptReload.cs.meta new file mode 100644 index 0000000..25a4663 --- /dev/null +++ b/Paths/Assets/Editor/DisableScriptReload.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 167133610e3f4b86aa272c1ae09494f3 +timeCreated: 1605283576 \ No newline at end of file