From 47ee45cbbe651a8f87ca2b8a3948f8b88db8211e Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:25:23 +0900 Subject: [PATCH] fix: editor crashed on exit play mode (editor, windows) close #351 --- Packages/src/Runtime/UIParticleUpdater.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Packages/src/Runtime/UIParticleUpdater.cs b/Packages/src/Runtime/UIParticleUpdater.cs index 4df5153..2e353e9 100644 --- a/Packages/src/Runtime/UIParticleUpdater.cs +++ b/Packages/src/Runtime/UIParticleUpdater.cs @@ -40,13 +40,26 @@ namespace Coffee.UIExtensions #if UNITY_EDITOR [InitializeOnLoadMethod] + private static void InitializeOnLoad() + { + UIExtraCallbacks.onAfterCanvasRebuild += Refresh; + + EditorApplication.playModeStateChanged += state => + { + UIExtraCallbacks.onAfterCanvasRebuild -= Refresh; + if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode) + { + UIExtraCallbacks.onAfterCanvasRebuild += Refresh; + } + }; + } #else [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] -#endif private static void InitializeOnLoad() { UIExtraCallbacks.onAfterCanvasRebuild += Refresh; } +#endif private static void Refresh() {