Skip to content

Commit

Permalink
fix: TextMeshPro objects appeared as black blocks when saving prefabs…
Browse files Browse the repository at this point in the history
… in prefab mode

close #285
  • Loading branch information
mob-sakai committed Dec 14, 2024
1 parent f39097a commit 9c648c6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Packages/src/Runtime/UIEffectBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")]
Expand Down Expand Up @@ -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<UIEffectBase>(FindObjectsSortMode.None))
foreach (var effect in FindObjectsByType<UIEffectBase>(FindObjectsSortMode.None)
#else
foreach (var effect in FindObjectsOfType<UIEffectBase>())
foreach (var effect in FindObjectsOfType<UIEffectBase>()
#endif
.Concat(GetAllComponentsInPrefabStage<UIEffectBase>()))
{
if (!effect.isActiveAndEnabled) continue;
if (!(effect.graphic is TextMeshProUGUI tmp) || !tmp.isActiveAndEnabled) continue;
Expand All @@ -259,6 +265,16 @@ private static void OnPostprocessAllAssets(string[] _, string[] __, string[] ___
EditorApplication.QueuePlayerLoopUpdate();
}
}

private static T[] GetAllComponentsInPrefabStage<T>() where T : Component
{
if (!PrefabStageUtility.GetCurrentPrefabStage()) return Array.Empty<T>();

var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (!prefabStage) return Array.Empty<T>();

return prefabStage.prefabContentsRoot.GetComponentsInChildren<T>(true);
}
#endif

#if UNITY_EDITOR
Expand Down

0 comments on commit 9c648c6

Please sign in to comment.