diff --git a/Packages/src/Runtime/UIEffectBase.cs b/Packages/src/Runtime/UIEffectBase.cs index 608e677d..cc4c5419 100644 --- a/Packages/src/Runtime/UIEffectBase.cs +++ b/Packages/src/Runtime/UIEffectBase.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using Coffee.UIEffectInternal; using UnityEngine; @@ -9,6 +11,9 @@ #if TMP_ENABLE using TMPro; #endif +#if UNITY_EDITOR +using UnityEditor.SceneManagement; +#endif [assembly: InternalsVisibleTo("UIEffect")] [assembly: InternalsVisibleTo("Coffee.UIEffect.Editor")] @@ -246,10 +251,11 @@ private static void OnPostprocessAllAssets(string[] _, string[] __, string[] ___ s_ShaderNameCache.Clear(); #if UNITY_2021_3 || UNITY_2022_2_OR_NEWER - foreach (var effect in FindObjectsByType(FindObjectsSortMode.None)) + foreach (var effect in FindObjectsByType(FindObjectsSortMode.None) #else - foreach (var effect in FindObjectsOfType()) + foreach (var effect in FindObjectsOfType() #endif + .Concat(GetAllComponentsInPrefabStage())) { if (!effect.isActiveAndEnabled) continue; if (!(effect.graphic is TextMeshProUGUI tmp) || !tmp.isActiveAndEnabled) continue; @@ -259,6 +265,16 @@ private static void OnPostprocessAllAssets(string[] _, string[] __, string[] ___ EditorApplication.QueuePlayerLoopUpdate(); } } + + private static T[] GetAllComponentsInPrefabStage() where T : Component + { + if (!PrefabStageUtility.GetCurrentPrefabStage()) return Array.Empty(); + + var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); + if (!prefabStage) return Array.Empty(); + + return prefabStage.prefabContentsRoot.GetComponentsInChildren(true); + } #endif #if UNITY_EDITOR