fix: Support for skipping "reload domain"

This commit is contained in:
mob-sakai
2026-06-25 03:15:09 +09:00
parent 514d5f0347
commit ec3fb13c11
5 changed files with 59 additions and 16 deletions
@@ -59,6 +59,21 @@ namespace Coffee.UIEffectInternal
s_BuildingPlayer = false; s_BuildingPlayer = false;
Initialize(); 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() private static void Initialize()
@@ -151,6 +166,10 @@ namespace Coffee.UIEffectInternal
protected virtual void OnInitialize() protected virtual void OnInitialize()
{ {
} }
protected virtual void OnDomainReload()
{
}
} }
internal abstract class PreloadedProjectSettingsEditor : Editor internal abstract class PreloadedProjectSettingsEditor : Editor
@@ -236,6 +255,11 @@ namespace Coffee.UIEffectInternal
break; break;
} }
} }
protected override void OnDomainReload()
{
s_Instance = null;
}
#else #else
public static T instance => s_Instance != null ? s_Instance : s_Instance = CreateInstance<T>(); public static T instance => s_Instance != null ? s_Instance : s_Instance = CreateInstance<T>();
#endif #endif
@@ -8,19 +8,19 @@ namespace Coffee.UIEffectInternal
{ {
private static readonly Dictionary<Type, IFrameCache> s_Caches = new Dictionary<Type, IFrameCache>(); private static readonly Dictionary<Type, IFrameCache> s_Caches = new Dictionary<Type, IFrameCache>();
static FrameCache() #if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
{
s_Caches.Clear();
UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache;
}
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#elif UNITY_EDITOR
[InitializeOnLoadMethod]
#else
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
#endif
private static void Clear() private static void Clear()
{ {
s_Caches.Clear(); s_Caches.Clear();
UIExtraCallbacks.onLateAfterCanvasRebuild -= ClearAllCache;
UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache;
} }
#endif
/// <summary> /// <summary>
/// Tries to retrieve a value from the frame cache with a specified key. /// Tries to retrieve a value from the frame cache with a specified key.
@@ -15,7 +15,7 @@ namespace Coffee.UIEffectInternal
public static Func<string, Shader> onShaderFind = Shader.Find; public static Func<string, Shader> onShaderFind = Shader.Find;
#if UNITY_EDITOR #if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
public static void Clear() public static void Clear()
{ {
@@ -1,5 +1,4 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
@@ -17,12 +16,26 @@ namespace Coffee.UIEffectInternal
private static readonly Dictionary<string, string> s_SampleNames = new Dictionary<string, string>(); private static readonly Dictionary<string, string> s_SampleNames = new Dictionary<string, string>();
private static readonly Dictionary<string, string> s_ShaderAliases = new Dictionary<string, string>(); private static readonly Dictionary<string, string> s_ShaderAliases = new Dictionary<string, string>();
#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) public static void RegisterShaderSamples((string shaderName, string sampleName, string version)[] samples)
{ {
if (IsBatchOrBuilding()) return; if (IsBatchOrBuilding()) return;
// Collect sample names. // Collect sample names.
s_Samples = samples; s_Samples = samples;
s_SampleNames.Clear();
foreach (var (shaderName, sampleName, _) in samples) foreach (var (shaderName, sampleName, _) in samples)
{ {
s_SampleNames[shaderName] = sampleName; s_SampleNames[shaderName] = sampleName;
@@ -156,12 +169,15 @@ namespace Coffee.UIEffectInternal
} }
// Remove deprecated shaders. // Remove deprecated shaders.
foreach (var (guid, fileName) in s_DeprecatedShaders) if (s_DeprecatedShaders != null)
{ {
var path = AssetDatabase.GUIDToAssetPath(guid); foreach (var (guid, fileName) in s_DeprecatedShaders)
if (!string.IsNullOrEmpty(path) && Path.GetFileName(path) == fileName)
{ {
AssetDatabase.DeleteAsset(path); var path = AssetDatabase.GUIDToAssetPath(guid);
if (!string.IsNullOrEmpty(path) && Path.GetFileName(path) == fileName)
{
AssetDatabase.DeleteAsset(path);
}
} }
} }
@@ -82,10 +82,13 @@ namespace Coffee.UIEffectInternal
message: "InitializeAfterCanvasRebuild"); message: "InitializeAfterCanvasRebuild");
} }
#if UNITY_EDITOR #if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#elif UNITY_EDITOR
[InitializeOnLoadMethod] [InitializeOnLoadMethod]
#endif #else
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
#endif
private static void InitializeOnLoad() private static void InitializeOnLoad()
{ {
Canvas.willRenderCanvases -= OnAfterCanvasRebuild; Canvas.willRenderCanvases -= OnAfterCanvasRebuild;