From ec3fb13c111638781bf852e2a4a4747fbfeb7d3a Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Thu, 25 Jun 2026 03:15:09 +0900 Subject: [PATCH] fix: Support for skipping "reload domain" --- .../PreloadedProjectSettings.cs | 24 +++++++++++++++++ .../Runtime/Internal/Utilities/FrameCache.cs | 16 ++++++------ .../Internal/Utilities/MaterialRepository.cs | 2 +- .../Utilities/ShaderSampleImporter.cs | 26 +++++++++++++++---- .../Internal/Utilities/UIExtraCallbacks.cs | 7 +++-- 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs b/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs index fac51f6..b1a4737 100644 --- a/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs +++ b/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs @@ -59,6 +59,21 @@ namespace Coffee.UIEffectInternal s_BuildingPlayer = false; Initialize(); } + +#if UNITY_2019_3_OR_NEWER + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + private static void OnDomainReload() + { + foreach (var t in TypeCache.GetTypesDerivedFrom(typeof(PreloadedProjectSettings<>))) + { + var defaultSettings = GetDefaultSettings(t); + if (defaultSettings != null) + { + defaultSettings.OnDomainReload(); + } + } + } +#endif } private static void Initialize() @@ -151,6 +166,10 @@ namespace Coffee.UIEffectInternal protected virtual void OnInitialize() { } + + protected virtual void OnDomainReload() + { + } } internal abstract class PreloadedProjectSettingsEditor : Editor @@ -236,6 +255,11 @@ namespace Coffee.UIEffectInternal break; } } + + protected override void OnDomainReload() + { + s_Instance = null; + } #else public static T instance => s_Instance != null ? s_Instance : s_Instance = CreateInstance(); #endif diff --git a/Packages/src/Runtime/Internal/Utilities/FrameCache.cs b/Packages/src/Runtime/Internal/Utilities/FrameCache.cs index 3a8b6e5..ba02ea9 100644 --- a/Packages/src/Runtime/Internal/Utilities/FrameCache.cs +++ b/Packages/src/Runtime/Internal/Utilities/FrameCache.cs @@ -8,19 +8,19 @@ namespace Coffee.UIEffectInternal { private static readonly Dictionary s_Caches = new Dictionary(); - static FrameCache() - { - s_Caches.Clear(); - UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache; - } - -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] +#elif UNITY_EDITOR + [InitializeOnLoadMethod] +#else + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] +#endif private static void Clear() { s_Caches.Clear(); + UIExtraCallbacks.onLateAfterCanvasRebuild -= ClearAllCache; + UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache; } -#endif /// /// Tries to retrieve a value from the frame cache with a specified key. diff --git a/Packages/src/Runtime/Internal/Utilities/MaterialRepository.cs b/Packages/src/Runtime/Internal/Utilities/MaterialRepository.cs index 49f7595..7692aec 100644 --- a/Packages/src/Runtime/Internal/Utilities/MaterialRepository.cs +++ b/Packages/src/Runtime/Internal/Utilities/MaterialRepository.cs @@ -15,7 +15,7 @@ namespace Coffee.UIEffectInternal public static Func onShaderFind = Shader.Find; -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] public static void Clear() { diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs index 290740c..850127f 100644 --- a/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs +++ b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs @@ -1,5 +1,4 @@ #if UNITY_EDITOR -using System; using System.Collections.Generic; using System.IO; using UnityEngine; @@ -17,12 +16,26 @@ namespace Coffee.UIEffectInternal private static readonly Dictionary s_SampleNames = new Dictionary(); private static readonly Dictionary s_ShaderAliases = new Dictionary(); +#if UNITY_2019_3_OR_NEWER + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] +#else + [InitializeOnLoadMethod] +#endif + private static void InitializeOnLoad() + { + s_Samples = null; + s_DeprecatedShaders = null; + s_SampleNames.Clear(); + s_ShaderAliases.Clear(); + } + public static void RegisterShaderSamples((string shaderName, string sampleName, string version)[] samples) { if (IsBatchOrBuilding()) return; // Collect sample names. s_Samples = samples; + s_SampleNames.Clear(); foreach (var (shaderName, sampleName, _) in samples) { s_SampleNames[shaderName] = sampleName; @@ -156,12 +169,15 @@ namespace Coffee.UIEffectInternal } // Remove deprecated shaders. - foreach (var (guid, fileName) in s_DeprecatedShaders) + if (s_DeprecatedShaders != null) { - var path = AssetDatabase.GUIDToAssetPath(guid); - if (!string.IsNullOrEmpty(path) && Path.GetFileName(path) == fileName) + foreach (var (guid, fileName) in s_DeprecatedShaders) { - AssetDatabase.DeleteAsset(path); + var path = AssetDatabase.GUIDToAssetPath(guid); + if (!string.IsNullOrEmpty(path) && Path.GetFileName(path) == fileName) + { + AssetDatabase.DeleteAsset(path); + } } } diff --git a/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs b/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs index 70ba7df..fd29036 100755 --- a/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs +++ b/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs @@ -82,10 +82,13 @@ namespace Coffee.UIEffectInternal message: "InitializeAfterCanvasRebuild"); } -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] +#elif UNITY_EDITOR [InitializeOnLoadMethod] -#endif +#else [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] +#endif private static void InitializeOnLoad() { Canvas.willRenderCanvases -= OnAfterCanvasRebuild;