Skip to content

Commit d8f9aab

Browse files
committed
fix the issue of truncated display of tmp text after using shadows
1 parent 958ba7f commit d8f9aab

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,23 @@ override public void UpdateGraphics(NGraphics graphics)
122122
if (_format.outline > 0)
123123
{
124124
graphics.ToggleKeyword("OUTLINE_ON", true);
125+
_material.EnableKeyword("OUTLINE_ON");
125126

126127
block.SetFloat(ShaderUtilities.ID_OutlineWidth, _format.outline);
127128
block.SetColor(ShaderUtilities.ID_OutlineColor, _format.outlineColor);
128129
}
129130
else
130131
{
131132
graphics.ToggleKeyword("OUTLINE_ON", false);
133+
_material.DisableKeyword("OUTLINE_ON");
132134

133135
block.SetFloat(ShaderUtilities.ID_OutlineWidth, 0);
134136
}
135137

136138
if (_format.shadowOffset.x != 0 || _format.shadowOffset.y != 0)
137139
{
138140
graphics.ToggleKeyword("UNDERLAY_ON", true);
141+
_material.EnableKeyword("UNDERLAY_ON");
139142

140143
block.SetColor(ShaderUtilities.ID_UnderlayColor, _format.shadowColor);
141144
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, _format.shadowOffset.x);
@@ -145,6 +148,7 @@ override public void UpdateGraphics(NGraphics graphics)
145148
else
146149
{
147150
graphics.ToggleKeyword("UNDERLAY_ON", false);
151+
_material.DisableKeyword("UNDERLAY_ON");
148152

149153
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, 0);
150154
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetY, 0);
@@ -272,9 +276,9 @@ TMP_Character GetCharacterFromFontAsset(uint unicode, FontStyles fontStyle)
272276
#pragma warning disable
273277
TMP_FontAsset actualAsset;
274278
#pragma warning restore
275-
return TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, _fontAsset, true, fontStyle, _fontWeight,
279+
return TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, _fontAsset, true, fontStyle, _fontWeight,
276280
out isAlternativeTypeface
277-
//,out actualAsset //old TMP version need this line
281+
//,out actualAsset //old TMP version need this line
278282
);
279283
}
280284

@@ -338,8 +342,8 @@ override public int DrawGlyph(float x, float y,
338342

339343
float u = (rect.x - _padding - _stylePadding) / _fontAsset.atlasWidth;
340344
float v = (rect.y - _padding - _stylePadding) / _fontAsset.atlasHeight;
341-
float uw = (rect.width + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasWidth;
342-
float vw = (rect.height + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasHeight;
345+
float uw = rect.width > 0 ? (rect.width + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasWidth : 0;
346+
float vw = rect.height > 0 ? (rect.height + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasHeight : 0;
343347

344348
uvBottomLeft = new Vector2(u, v);
345349
uvTopLeft = new Vector2(u, v + vw);

0 commit comments

Comments
 (0)