Skip to content

Commit 067fd10

Browse files
author
Unity Technologies
committed
com.unity.textmeshpro@3.2.0-pre.8
## [3.2.0-pre.8] - 2024-01-30 ### Changes - Fix Dropdown creation causing a crash after undoing. - Addressed issue surrounding dropdown not closing correctly in certain situations - Resolves issue in editor where a null mesh may be set with still present submesh data, not having the canvas update. - Ensure enabling and disabling Canvases does not cause a regeneration of the text. - Fixed un-detected sprite asset changes after adding new sprites. - Ensure Kerning is not applied to Sprites
1 parent aee719b commit 067fd10

8 files changed

+76
-48
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22
These are the release notes for the TextMesh Pro UPM package which was first introduced with Unity 2018.1. Please see the following link for the Release Notes for prior versions of TextMesh Pro. http://digitalnativestudios.com/forum/index.php?topic=1363.0
33

4+
## [3.2.0-pre.8] - 2024-01-30
5+
### Changes
6+
- Fix Dropdown creation causing a crash after undoing.
7+
- Addressed issue surrounding dropdown not closing correctly in certain situations
8+
- Resolves issue in editor where a null mesh may be set with still present submesh data, not having the canvas update.
9+
- Ensure enabling and disabling Canvases does not cause a regeneration of the text.
10+
- Fixed un-detected sprite asset changes after adding new sprites.
11+
- Ensure Kerning is not applied to Sprites
412

513
## [3.2.0-pre.7] - 2023-12-17
614
### Changes

Scripts/Editor/TMP_SpriteAssetMenu.cs

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
178178
spriteAsset.SortGlyphTable();
179179
spriteAsset.UpdateLookupTables();
180180
TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);
181+
EditorUtility.SetDirty(spriteAsset);
181182

182183
}
183184

Scripts/Runtime/TMP_DefaultControls.cs

+52-32
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,27 @@ private static GameObject CreateUIElementRoot(string name, Vector2 size)
4040
GameObject root;
4141

4242
#if UNITY_EDITOR
43-
root = ObjectFactory.CreateGameObject(name);
43+
root = ObjectFactory.CreateGameObject(name, typeof(RectTransform));
44+
var rt = root.GetComponent<RectTransform>();
45+
rt.sizeDelta = size;
4446
#else
4547
root = new GameObject(name);
46-
#endif
47-
4848
RectTransform rectTransform = root.AddComponent<RectTransform>();
4949
rectTransform.sizeDelta = size;
50+
#endif
51+
5052
return root;
5153
}
5254

5355
static GameObject CreateUIObject(string name, GameObject parent)
5456
{
55-
GameObject go = new GameObject(name);
57+
GameObject go;
58+
#if UNITY_EDITOR
59+
go = ObjectFactory.CreateGameObject(name, typeof(RectTransform));
60+
#else
61+
go = new GameObject(name);
5662
go.AddComponent<RectTransform>();
63+
#endif
5764
SetParentAndAlign(go, parent);
5865
return go;
5966
}
@@ -102,12 +109,12 @@ public static GameObject CreateScrollbar(Resources resources)
102109
GameObject sliderArea = CreateUIObject("Sliding Area", scrollbarRoot);
103110
GameObject handle = CreateUIObject("Handle", sliderArea);
104111

105-
Image bgImage = scrollbarRoot.AddComponent<Image>();
112+
Image bgImage = AddComponent<Image>(scrollbarRoot);
106113
bgImage.sprite = resources.background;
107114
bgImage.type = Image.Type.Sliced;
108115
bgImage.color = s_DefaultSelectableColor;
109116

110-
Image handleImage = handle.AddComponent<Image>();
117+
Image handleImage = AddComponent<Image>(handle);
111118
handleImage.sprite = resources.standard;
112119
handleImage.type = Image.Type.Sliced;
113120
handleImage.color = s_DefaultSelectableColor;
@@ -120,7 +127,7 @@ public static GameObject CreateScrollbar(Resources resources)
120127
RectTransform handleRect = handle.GetComponent<RectTransform>();
121128
handleRect.sizeDelta = new Vector2(20, 20);
122129

123-
Scrollbar scrollbar = scrollbarRoot.AddComponent<Scrollbar>();
130+
Scrollbar scrollbar = AddComponent<Scrollbar>(scrollbarRoot);
124131
scrollbar.handleRect = handleRect;
125132
scrollbar.targetGraphic = handleImage;
126133
SetDefaultColorTransitionValues(scrollbar);
@@ -132,19 +139,25 @@ public static GameObject CreateButton(Resources resources)
132139
{
133140
GameObject buttonRoot = CreateUIElementRoot("Button", s_ThickElementSize);
134141

135-
GameObject childText = new GameObject("Text (TMP)");
142+
GameObject childText;
143+
#if UNITY_EDITOR
144+
childText = ObjectFactory.CreateGameObject("Text (TMP)", typeof(RectTransform));
145+
#else
146+
childText = new GameObject("Text (TMP)");
136147
childText.AddComponent<RectTransform>();
148+
#endif
149+
137150
SetParentAndAlign(childText, buttonRoot);
138151

139-
Image image = buttonRoot.AddComponent<Image>();
152+
Image image = AddComponent<Image>(buttonRoot);
140153
image.sprite = resources.standard;
141154
image.type = Image.Type.Sliced;
142155
image.color = s_DefaultSelectableColor;
143156

144-
Button bt = buttonRoot.AddComponent<Button>();
157+
Button bt = AddComponent<Button>(buttonRoot);
145158
SetDefaultColorTransitionValues(bt);
146159

147-
TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
160+
TextMeshProUGUI text = AddComponent<TextMeshProUGUI>(childText);
148161
text.text = "Button";
149162
text.alignment = TextAlignmentOptions.Center;
150163
SetDefaultTextValues(text);
@@ -162,8 +175,7 @@ public static GameObject CreateText(Resources resources)
162175
GameObject go = null;
163176

164177
#if UNITY_EDITOR
165-
go = ObjectFactory.CreateGameObject("Text (TMP)");
166-
ObjectFactory.AddComponent<TextMeshProUGUI>(go);
178+
go = ObjectFactory.CreateGameObject("Text (TMP)", typeof(TextMeshProUGUI));
167179
#else
168180
go = CreateUIElementRoot("Text (TMP)", s_TextElementSize);
169181
go.AddComponent<TextMeshProUGUI>();
@@ -172,7 +184,6 @@ public static GameObject CreateText(Resources resources)
172184
return go;
173185
}
174186

175-
176187
public static GameObject CreateInputField(Resources resources)
177188
{
178189
GameObject root = CreateUIElementRoot("InputField (TMP)", s_ThickElementSize);
@@ -181,15 +192,15 @@ public static GameObject CreateInputField(Resources resources)
181192
GameObject childPlaceholder = CreateUIObject("Placeholder", textArea);
182193
GameObject childText = CreateUIObject("Text", textArea);
183194

184-
Image image = root.AddComponent<Image>();
195+
Image image = AddComponent<Image>(root);
185196
image.sprite = resources.inputField;
186197
image.type = Image.Type.Sliced;
187198
image.color = s_DefaultSelectableColor;
188199

189-
TMP_InputField inputField = root.AddComponent<TMP_InputField>();
200+
TMP_InputField inputField = AddComponent<TMP_InputField>(root);
190201
SetDefaultColorTransitionValues(inputField);
191202

192-
RectMask2D rectMask = textArea.AddComponent<RectMask2D>();
203+
RectMask2D rectMask = AddComponent<RectMask2D>(textArea);
193204
rectMask.padding = new Vector4(-8, -5, -8, -5);
194205

195206
RectTransform textAreaRectTransform = textArea.GetComponent<RectTransform>();
@@ -200,14 +211,14 @@ public static GameObject CreateInputField(Resources resources)
200211
textAreaRectTransform.offsetMax = new Vector2(-10, -7);
201212

202213

203-
TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
214+
TextMeshProUGUI text = AddComponent<TextMeshProUGUI>(childText);
204215
text.text = "";
205216
text.textWrappingMode = TextWrappingModes.NoWrap;
206217
text.extraPadding = true;
207218
text.richText = true;
208219
SetDefaultTextValues(text);
209220

210-
TextMeshProUGUI placeholder = childPlaceholder.AddComponent<TextMeshProUGUI>();
221+
TextMeshProUGUI placeholder = AddComponent<TextMeshProUGUI>(childPlaceholder);
211222
placeholder.text = "Enter text...";
212223
placeholder.fontSize = 14;
213224
placeholder.fontStyle = FontStyles.Italic;
@@ -220,7 +231,7 @@ public static GameObject CreateInputField(Resources resources)
220231
placeholder.color = placeholderColor;
221232

222233
// Add Layout component to placeholder.
223-
placeholder.gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
234+
AddComponent<LayoutElement>(placeholder.gameObject).ignoreLayout = true;
224235

225236
RectTransform textRectTransform = childText.GetComponent<RectTransform>();
226237
textRectTransform.anchorMin = Vector2.zero;
@@ -275,28 +286,28 @@ public static GameObject CreateDropdown(Resources resources)
275286

276287
// Setup item UI components.
277288

278-
TextMeshProUGUI itemLabelText = itemLabel.AddComponent<TextMeshProUGUI>();
289+
TextMeshProUGUI itemLabelText = AddComponent<TextMeshProUGUI>(itemLabel);
279290
SetDefaultTextValues(itemLabelText);
280291
itemLabelText.alignment = TextAlignmentOptions.Left;
281292

282-
Image itemBackgroundImage = itemBackground.AddComponent<Image>();
293+
Image itemBackgroundImage = AddComponent<Image>(itemBackground);
283294
itemBackgroundImage.color = new Color32(245, 245, 245, 255);
284295

285-
Image itemCheckmarkImage = itemCheckmark.AddComponent<Image>();
296+
Image itemCheckmarkImage = AddComponent<Image>(itemCheckmark);
286297
itemCheckmarkImage.sprite = resources.checkmark;
287298

288-
Toggle itemToggle = item.AddComponent<Toggle>();
299+
Toggle itemToggle = AddComponent<Toggle>(item);
289300
itemToggle.targetGraphic = itemBackgroundImage;
290301
itemToggle.graphic = itemCheckmarkImage;
291302
itemToggle.isOn = true;
292303

293304
// Setup template UI components.
294305

295-
Image templateImage = template.AddComponent<Image>();
306+
Image templateImage = AddComponent<Image>(template);
296307
templateImage.sprite = resources.standard;
297308
templateImage.type = Image.Type.Sliced;
298309

299-
ScrollRect templateScrollRect = template.AddComponent<ScrollRect>();
310+
ScrollRect templateScrollRect = AddComponent<ScrollRect>(template);
300311
templateScrollRect.content = (RectTransform)content.transform;
301312
templateScrollRect.viewport = (RectTransform)viewport.transform;
302313
templateScrollRect.horizontal = false;
@@ -305,28 +316,28 @@ public static GameObject CreateDropdown(Resources resources)
305316
templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
306317
templateScrollRect.verticalScrollbarSpacing = -3;
307318

308-
Mask scrollRectMask = viewport.AddComponent<Mask>();
319+
Mask scrollRectMask = AddComponent<Mask>(viewport);
309320
scrollRectMask.showMaskGraphic = false;
310321

311-
Image viewportImage = viewport.AddComponent<Image>();
322+
Image viewportImage = AddComponent<Image>(viewport);
312323
viewportImage.sprite = resources.mask;
313324
viewportImage.type = Image.Type.Sliced;
314325

315326
// Setup dropdown UI components.
316327

317-
TextMeshProUGUI labelText = label.AddComponent<TextMeshProUGUI>();
328+
TextMeshProUGUI labelText = AddComponent<TextMeshProUGUI>(label);
318329
SetDefaultTextValues(labelText);
319330
labelText.alignment = TextAlignmentOptions.Left;
320331

321-
Image arrowImage = arrow.AddComponent<Image>();
332+
Image arrowImage = AddComponent<Image>(arrow);
322333
arrowImage.sprite = resources.dropdown;
323334

324-
Image backgroundImage = root.AddComponent<Image>();
335+
Image backgroundImage = AddComponent<Image>(root);
325336
backgroundImage.sprite = resources.standard;
326337
backgroundImage.color = s_DefaultSelectableColor;
327338
backgroundImage.type = Image.Type.Sliced;
328339

329-
TMP_Dropdown dropdown = root.AddComponent<TMP_Dropdown>();
340+
TMP_Dropdown dropdown = AddComponent<TMP_Dropdown>(root);
330341
dropdown.targetGraphic = backgroundImage;
331342
SetDefaultColorTransitionValues(dropdown);
332343
dropdown.template = template.GetComponent<RectTransform>();
@@ -400,5 +411,14 @@ public static GameObject CreateDropdown(Resources resources)
400411

401412
return root;
402413
}
414+
415+
private static T AddComponent<T>(GameObject go) where T : Component
416+
{
417+
#if UNITY_EDITOR
418+
return ObjectFactory.AddComponent<T>(go);
419+
#else
420+
return go.AddComponent<T>();
421+
#endif
422+
}
403423
}
404424
}

Scripts/Runtime/TMP_Text.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4168,12 +4168,13 @@ protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 m
41684168
#region Handle Kerning
41694169
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
41704170
float characterSpacingAdjustment = m_characterSpacing;
4171-
if (m_enableKerning)
4171+
// Make sure the current character and the next are Characters (not Sprite).
4172+
if (m_enableKerning && m_textElementType == TMP_TextElementType.Character)
41724173
{
41734174
GlyphPairAdjustmentRecord adjustmentPair;
41744175
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;
41754176

4176-
if (m_characterCount < totalCharacterCount - 1)
4177+
if (m_characterCount < totalCharacterCount - 1 && m_textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
41774178
{
41784179
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
41794180
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
@@ -4190,7 +4191,7 @@ protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 m
41904191
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
41914192
uint key = baseGlyphIndex << 16 | previousGlyphIndex;
41924193

4193-
if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
4194+
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
41944195
{
41954196
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
41964197
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;

Scripts/Runtime/TextMeshPro.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2558,14 +2558,14 @@ protected virtual void GenerateTextMesh()
25582558
#region Handle Kerning
25592559
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
25602560
float characterSpacingAdjustment = m_characterSpacing;
2561-
if (kerning)
2561+
if (kerning && m_textElementType == TMP_TextElementType.Character)
25622562
{
25632563
k_HandleGPOSFeaturesMarker.Begin();
25642564

25652565
GlyphPairAdjustmentRecord adjustmentPair;
25662566
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;
25672567

2568-
if (m_characterCount < totalCharacterCount - 1)
2568+
if (m_characterCount < totalCharacterCount - 1 && m_textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
25692569
{
25702570
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
25712571
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
@@ -2582,7 +2582,7 @@ protected virtual void GenerateTextMesh()
25822582
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
25832583
uint key = baseGlyphIndex << 16 | previousGlyphIndex;
25842584

2585-
if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
2585+
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
25862586
{
25872587
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
25882588
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;

Scripts/Runtime/TextMeshProUGUI.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,6 @@ protected override void OnCanvasHierarchyChanged()
22912291
TMP_UpdateManager.UnRegisterTextObjectForUpdate(this);
22922292
else if (m_IsTextObjectScaleStatic == false)
22932293
TMP_UpdateManager.RegisterTextObjectForUpdate(this);
2294-
2295-
m_havePropertiesChanged = true;
22962294
}
22972295

22982296

@@ -2911,14 +2909,14 @@ protected virtual void GenerateTextMesh()
29112909
#region Handle Kerning
29122910
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
29132911
float characterSpacingAdjustment = m_characterSpacing;
2914-
if (kerning)
2912+
if (kerning && m_textElementType == TMP_TextElementType.Character)
29152913
{
29162914
k_HandleGPOSFeaturesMarker.Begin();
29172915

29182916
GlyphPairAdjustmentRecord adjustmentPair;
29192917
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;
29202918

2921-
if (m_characterCount < totalCharacterCount - 1)
2919+
if (m_characterCount < totalCharacterCount - 1 && textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
29222920
{
29232921
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
29242922
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
@@ -2935,7 +2933,7 @@ protected virtual void GenerateTextMesh()
29352933
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
29362934
uint key = baseGlyphIndex << 16 | previousGlyphIndex;
29372935

2938-
if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
2936+
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
29392937
{
29402938
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
29412939
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;

ValidationExceptions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[
44
{
55
"ValidationTest": "API Validation",
6-
"PackageVersion": "3.2.0-pre.2"
6+
"PackageVersion": "3.2.0-pre.8"
77
}
88
]
99
}

0 commit comments

Comments
 (0)