Skip to content

Commit

Permalink
fix: TextMeshProUGUI disappears when the Y-axis scale is changed
Browse files Browse the repository at this point in the history
close #286
  • Loading branch information
mob-sakai committed Dec 24, 2024
1 parent bc11095 commit 9d98c5d
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions Packages/src/Runtime/UIEffectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@ public virtual UIEffectContext context

protected override void OnEnable()
{
UIExtraCallbacks.onScreenSizeChangedAction += SetVerticesDirtyIfTextMeshPro;
#if TMP_ENABLE
if (graphic is TextMeshProUGUI)
{
_prevLossyScaleY = transform.lossyScale.y;
UIExtraCallbacks.onAfterCanvasRebuild += CheckSDFScaleForTMP;
UIExtraCallbacks.onScreenSizeChangedAction += SetVerticesDirtyForTMP;
}
#endif

UpdateContext(context);
SetMaterialDirty();
SetVerticesDirty();
}

protected override void OnDisable()
{
UIExtraCallbacks.onScreenSizeChangedAction -= SetVerticesDirtyIfTextMeshPro;
#if TMP_ENABLE
UIExtraCallbacks.onScreenSizeChangedAction -= SetVerticesDirtyForTMP;
UIExtraCallbacks.onAfterCanvasRebuild -= CheckSDFScaleForTMP;
#endif

MaterialRepository.Release(ref _material);
SetMaterialDirty();
SetVerticesDirty();
Expand Down Expand Up @@ -200,18 +212,6 @@ public virtual void SetVerticesDirty()
}
}


private void SetVerticesDirtyIfTextMeshPro()
{
#if TMP_ENABLE
if (graphic && graphic.isActiveAndEnabled
&& (graphic is TextMeshProUGUI || graphic is TMP_SubMeshUI))
{
graphic.SetVerticesDirty();
}
#endif
}

public virtual void SetMaterialDirty()
{
if (graphic)
Expand Down Expand Up @@ -348,6 +348,28 @@ private static TMP_SubMeshUI GetSubMeshUI(List<TMP_SubMeshUI> subMeshes, Materia

return null;
}

private void SetVerticesDirtyForTMP()
{
if (graphic && graphic.isActiveAndEnabled)
{
graphic.SetVerticesDirty();
}
}

private void CheckSDFScaleForTMP()
{
var lossyScaleY = transform.lossyScale.y;
if (Mathf.Approximately(_prevLossyScaleY, lossyScaleY)) return;

_prevLossyScaleY = lossyScaleY;
if (graphic is TextMeshProUGUI textMeshProUGUI && graphic.isActiveAndEnabled)
{
OnTMPChanged(textMeshProUGUI);
}
}

private float _prevLossyScaleY;
#endif

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

0 comments on commit 9d98c5d

Please sign in to comment.