Skip to content

Commit d3779f9

Browse files
committed
fix: UIEffect may not work correctly when using FallbackAtlas with TextMeshProUGUI
close #298
1 parent 213daa8 commit d3779f9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Packages/src/Runtime/UIEffectBase.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static void OnTMPChanged(TextMeshProUGUI textMeshProUGUI)
258258
}
259259
else if (i - 1 < subMeshes.Count)
260260
{
261-
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material);
261+
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, i - 1);
262262
if (!target || !subMeshUI) break;
263263

264264
var replica = subMeshUI.GetOrAddComponent<UIEffectReplica>();
@@ -285,11 +285,13 @@ private static void OnTMPChanged(TextMeshProUGUI textMeshProUGUI)
285285
s_Mesh.Clear(false);
286286
}
287287

288-
private static TMP_SubMeshUI GetSubMeshUI(List<TMP_SubMeshUI> subMeshes, Material material)
288+
private static TMP_SubMeshUI GetSubMeshUI(List<TMP_SubMeshUI> subMeshes, Material material, int start)
289289
{
290-
for (var j = 0; j < subMeshes.Count; j++)
290+
var count = subMeshes.Count;
291+
for (var j = 0; j < count; j++)
291292
{
292-
if (subMeshes[j].sharedMaterial == material) return subMeshes[j];
293+
var s = subMeshes[(j + start + count) % count];
294+
if (s.sharedMaterial == material) return s;
293295
}
294296

295297
return null;

0 commit comments

Comments
 (0)