Skip to content

Commit 9d98c5d

Browse files
committed
fix: TextMeshProUGUI disappears when the Y-axis scale is changed
close #286
1 parent bc11095 commit 9d98c5d

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

Packages/src/Runtime/UIEffectBase.cs

+36-14
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,27 @@ public virtual UIEffectContext context
5252

5353
protected override void OnEnable()
5454
{
55-
UIExtraCallbacks.onScreenSizeChangedAction += SetVerticesDirtyIfTextMeshPro;
55+
#if TMP_ENABLE
56+
if (graphic is TextMeshProUGUI)
57+
{
58+
_prevLossyScaleY = transform.lossyScale.y;
59+
UIExtraCallbacks.onAfterCanvasRebuild += CheckSDFScaleForTMP;
60+
UIExtraCallbacks.onScreenSizeChangedAction += SetVerticesDirtyForTMP;
61+
}
62+
#endif
63+
5664
UpdateContext(context);
5765
SetMaterialDirty();
5866
SetVerticesDirty();
5967
}
6068

6169
protected override void OnDisable()
6270
{
63-
UIExtraCallbacks.onScreenSizeChangedAction -= SetVerticesDirtyIfTextMeshPro;
71+
#if TMP_ENABLE
72+
UIExtraCallbacks.onScreenSizeChangedAction -= SetVerticesDirtyForTMP;
73+
UIExtraCallbacks.onAfterCanvasRebuild -= CheckSDFScaleForTMP;
74+
#endif
75+
6476
MaterialRepository.Release(ref _material);
6577
SetMaterialDirty();
6678
SetVerticesDirty();
@@ -200,18 +212,6 @@ public virtual void SetVerticesDirty()
200212
}
201213
}
202214

203-
204-
private void SetVerticesDirtyIfTextMeshPro()
205-
{
206-
#if TMP_ENABLE
207-
if (graphic && graphic.isActiveAndEnabled
208-
&& (graphic is TextMeshProUGUI || graphic is TMP_SubMeshUI))
209-
{
210-
graphic.SetVerticesDirty();
211-
}
212-
#endif
213-
}
214-
215215
public virtual void SetMaterialDirty()
216216
{
217217
if (graphic)
@@ -348,6 +348,28 @@ private static TMP_SubMeshUI GetSubMeshUI(List<TMP_SubMeshUI> subMeshes, Materia
348348

349349
return null;
350350
}
351+
352+
private void SetVerticesDirtyForTMP()
353+
{
354+
if (graphic && graphic.isActiveAndEnabled)
355+
{
356+
graphic.SetVerticesDirty();
357+
}
358+
}
359+
360+
private void CheckSDFScaleForTMP()
361+
{
362+
var lossyScaleY = transform.lossyScale.y;
363+
if (Mathf.Approximately(_prevLossyScaleY, lossyScaleY)) return;
364+
365+
_prevLossyScaleY = lossyScaleY;
366+
if (graphic is TextMeshProUGUI textMeshProUGUI && graphic.isActiveAndEnabled)
367+
{
368+
OnTMPChanged(textMeshProUGUI);
369+
}
370+
}
371+
372+
private float _prevLossyScaleY;
351373
#endif
352374

353375
public abstract void SetRate(float rate, UIEffectTweener.CullingMask cullingMask);

0 commit comments

Comments
 (0)