Skip to content

Commit 6df08ea

Browse files
author
Unity Technologies
committed
com.unity.textmeshpro@1.5.0-preview.12
## [1.5.0-preview.12] - 2020-05-09 ## [2.1.0-preview.12] ## [3.0.0-preview.12] ### Changes - Added synchronization of the RaycastTarget property of the parent <TextMeshProUGUI> with potential child sub text objects. Case #1240784 - Fixed Font Asset Bold Spacing adjustment scaling based on the text object point size instead of current point size. Case #1241132 - Improved text alignment when using RTL in conjunction with character, word and other spacing adjustments. - Fixed TMP Input Field caret potentially not being visible when reaching the right side of the viewport. See [forum post](https://forum.unity.com/threads/inputfield-bug-2.879244/) for more details. - Fixed TMP Input Field incorrect text RectTransform horizontal adjustment when using the Backspace key. See [forum post](https://forum.unity.com/threads/inputfield-bug4-delete-and-backspace-bug.879283/) for more details. - Fixed potential null reference in the TextMeshProUGUI.Cull function when using a workflow that involves enabling / disabling Canvases in the scene. - Fixed ArgumentOutOfRangeException when using the "Update Sprite Asset" inspector option on a sprite asset that does not contain any sprites. Case #1242936 - Fixed incorrect culling of the text geometry by the RectMask2D component on newly created text objects. Case #1245445 - It is now possible to use the Material Context Menu options to Copy / Paste Material Properties or Atlas Texture originally created for TMP with all other non TMP specific materials. Case #1242671 - Fixed NullReferenceException when setting the Atlas Texture to None in the Debug Settings of the Material Inspector of a text object. Case #1245104
1 parent 45f7472 commit 6df08ea

17 files changed

+270
-164
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
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+
## [1.5.0-preview.12] - 2020-05-09
5+
## [2.1.0-preview.12]
6+
## [3.0.0-preview.12]
7+
### Changes
8+
- Added synchronization of the RaycastTarget property of the parent <TextMeshProUGUI> with potential child sub text objects. Case #1240784
9+
- Fixed Font Asset Bold Spacing adjustment scaling based on the text object point size instead of current point size. Case #1241132
10+
- Improved text alignment when using RTL in conjunction with character, word and other spacing adjustments.
11+
- Fixed TMP Input Field caret potentially not being visible when reaching the right side of the viewport. See [forum post](https://forum.unity.com/threads/inputfield-bug-2.879244/) for more details.
12+
- Fixed TMP Input Field incorrect text RectTransform horizontal adjustment when using the Backspace key. See [forum post](https://forum.unity.com/threads/inputfield-bug4-delete-and-backspace-bug.879283/) for more details.
13+
- Fixed potential null reference in the TextMeshProUGUI.Cull function when using a workflow that involves enabling / disabling Canvases in the scene.
14+
- Fixed ArgumentOutOfRangeException when using the "Update Sprite Asset" inspector option on a sprite asset that does not contain any sprites. Case #1242936
15+
- Fixed incorrect culling of the text geometry by the RectMask2D component on newly created text objects. Case #1245445
16+
- It is now possible to use the Material Context Menu options to Copy / Paste Material Properties or Atlas Texture originally created for TMP with all other non TMP specific materials. Case #1242671
17+
- Fixed NullReferenceException when setting the Atlas Texture to None in the Debug Settings of the Material Inspector of a text object. Case #1245104
18+
419
## [1.5.0-preview.11] - 2020-04-22
520
## [2.1.0-preview.11]
621
## [3.0.0-preview.11]

Scripts/Editor/TMP_SettingsEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal class Styles
2727
public static readonly GUIContent textMeshProUiLabel = new GUIContent("TextMeshPro UI");
2828
public static readonly GUIContent enableRaycastTarget = new GUIContent("Enable Raycast Target");
2929
public static readonly GUIContent autoSizeContainerLabel = new GUIContent("Auto Size Text Container", "Set the size of the text container to match the text.");
30+
public static readonly GUIContent isTextObjectScaleStaticLabel = new GUIContent("Is Object Scale Static", "Disables calling InternalUpdate() when enabled. This can improve performance when text object scale is static.");
3031

3132
public static readonly GUIContent textComponentDefaultSettingsLabel = new GUIContent("Text Component Default Settings");
3233
public static readonly GUIContent defaultFontSize = new GUIContent("Default Font Size");
@@ -73,6 +74,7 @@ internal class Styles
7374
SerializedProperty m_PropDefaultTextMeshProUITextContainerSize;
7475
SerializedProperty m_PropAutoSizeTextContainer;
7576
SerializedProperty m_PropEnableRaycastTarget;
77+
SerializedProperty m_PropIsTextObjectScaleStatic;
7678

7779
SerializedProperty m_PropSpriteAsset;
7880
SerializedProperty m_PropMissingSpriteCharacterUnicode;
@@ -120,6 +122,7 @@ public void OnEnable()
120122
m_PropDefaultTextMeshProUITextContainerSize = serializedObject.FindProperty("m_defaultTextMeshProUITextContainerSize");
121123
m_PropAutoSizeTextContainer = serializedObject.FindProperty("m_autoSizeTextContainer");
122124
m_PropEnableRaycastTarget = serializedObject.FindProperty("m_EnableRaycastTarget");
125+
m_PropIsTextObjectScaleStatic = serializedObject.FindProperty("m_IsTextObjectScaleStatic");
123126

124127
m_PropSpriteAsset = serializedObject.FindProperty("m_defaultSpriteAsset");
125128
m_PropMissingSpriteCharacterUnicode = serializedObject.FindProperty("m_MissingCharacterSpriteUnicode");
@@ -223,6 +226,7 @@ public override void OnInspectorGUI()
223226
EditorGUILayout.PropertyField(m_PropDefaultTextMeshProUITextContainerSize, Styles.textMeshProUiLabel);
224227
EditorGUILayout.PropertyField(m_PropEnableRaycastTarget, Styles.enableRaycastTarget);
225228
EditorGUILayout.PropertyField(m_PropAutoSizeTextContainer, Styles.autoSizeContainerLabel);
229+
EditorGUILayout.PropertyField(m_PropIsTextObjectScaleStatic, Styles.isTextObjectScaleStaticLabel);
226230
EditorGUI.indentLevel = 0;
227231

228232
EditorGUILayout.Space();

Scripts/Editor/TMP_SpriteAssetMenu.cs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace TMPro.EditorUtilities
1212
{
13-
1413
public static class TMP_SpriteAssetMenu
1514
{
1615
// Add a Context Menu to the Sprite Asset Editor Panel to Create and Add a Default Material.
@@ -48,39 +47,70 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
4847
if (string.IsNullOrEmpty(filePath))
4948
return;
5049

51-
// Get all the Sprites sorted Left to Right / Top to Bottom
52-
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).OrderByDescending(x => x.rect.y).ThenBy(x => x.rect.x).ToArray();
50+
// Get all the sprites defined in the sprite sheet texture referenced by this sprite asset.
51+
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).ToArray();
52+
53+
// Return if sprite sheet texture does not have any sprites defined in it.
54+
if (sprites.Length == 0)
55+
{
56+
Debug.Log("Sprite Asset <color=#FFFF80>[" + spriteAsset.name + "]</color>'s atlas texture does not appear to have any sprites defined in it. Use the Unity Sprite Editor to define sprites for this texture.", spriteAsset.spriteSheet);
57+
return;
58+
}
5359

5460
List<TMP_SpriteGlyph> spriteGlyphTable = spriteAsset.spriteGlyphTable;
5561

56-
// Finding available glyph indexes to insert new glyphs into.
57-
var tempGlyphTable = spriteGlyphTable.OrderBy(glyph => glyph.index).ToList();
62+
// Find available glpyh indexes
63+
uint[] existingGlyphIndexes = spriteGlyphTable.Select(x => x.index).ToArray();
5864
List<uint> availableGlyphIndexes = new List<uint>();
5965

66+
uint lastGlyphIndex = existingGlyphIndexes.Length > 0 ? existingGlyphIndexes.Last() : 0;
6067
int elementIndex = 0;
61-
for (uint i = 0; i < tempGlyphTable[tempGlyphTable.Count - 1].index; i++)
68+
for (uint i = 0; i < lastGlyphIndex; i++)
6269
{
63-
uint currentElementIndex = tempGlyphTable[elementIndex].index;
70+
uint existingGlyphIndex = existingGlyphIndexes[elementIndex];
6471

65-
if (i == currentElementIndex)
72+
if (i == existingGlyphIndex)
6673
elementIndex += 1;
6774
else
6875
availableGlyphIndexes.Add(i);
6976
}
7077

71-
// Iterate over each of the sprites in the texture to try to match them to existing sprites in the sprite asset.
78+
// Iterate over sprites contained in the updated sprite sheet to identify new and / or modified sprites.
7279
for (int i = 0; i < sprites.Length; i++)
7380
{
74-
int id = sprites[i].GetInstanceID();
81+
Sprite sprite = sprites[i];
7582

76-
int glyphIndex = spriteGlyphTable.FindIndex(item => item.sprite.GetInstanceID() == id);
83+
// Check if current sprites is already contained in the sprite glyph table of the sprite asset.
84+
TMP_SpriteGlyph spriteGlyph = spriteGlyphTable.FirstOrDefault(x => x.sprite == sprite);
7785

78-
if (glyphIndex == -1)
86+
if (spriteGlyph != null)
7987
{
80-
// Add new Sprite Glyph to the table
81-
Sprite sprite = sprites[i];
88+
// update existing sprite glyph
89+
if (spriteGlyph.glyphRect.x != sprite.rect.x || spriteGlyph.glyphRect.y != sprite.rect.y || spriteGlyph.glyphRect.width != sprite.rect.width || spriteGlyph.glyphRect.height != sprite.rect.height)
90+
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
91+
}
92+
else
93+
{
94+
TMP_SpriteCharacter spriteCharacter;
95+
96+
// Check if this sprite potentially exists under the same name in the sprite character table.
97+
if (spriteAsset.spriteCharacterTable != null && spriteAsset.spriteCharacterTable.Count > 0)
98+
{
99+
spriteCharacter = spriteAsset.spriteCharacterTable.FirstOrDefault(x => x.name == sprite.name);
100+
spriteGlyph = spriteCharacter != null ? spriteGlyphTable[(int)spriteCharacter.glyphIndex] : null;
82101

83-
TMP_SpriteGlyph spriteGlyph = new TMP_SpriteGlyph();
102+
if (spriteGlyph != null)
103+
{
104+
// Update sprite reference and data
105+
spriteGlyph.sprite = sprite;
106+
107+
if (spriteGlyph.glyphRect.x != sprite.rect.x || spriteGlyph.glyphRect.y != sprite.rect.y || spriteGlyph.glyphRect.width != sprite.rect.width || spriteGlyph.glyphRect.height != sprite.rect.height)
108+
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
109+
}
110+
}
111+
112+
// Add new Sprite Glyph to the table
113+
spriteGlyph = new TMP_SpriteGlyph();
84114

85115
// Get available glyph index
86116
if (availableGlyphIndexes.Count > 0)
@@ -98,23 +128,12 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
98128

99129
spriteGlyphTable.Add(spriteGlyph);
100130

101-
TMP_SpriteCharacter spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
131+
spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
102132
spriteCharacter.name = sprite.name;
103133
spriteCharacter.scale = 1.0f;
104134

105135
spriteAsset.spriteCharacterTable.Add(spriteCharacter);
106136
}
107-
else
108-
{
109-
// Look for changes in existing Sprite Glyph
110-
Sprite sprite = sprites[i];
111-
112-
TMP_SpriteGlyph spriteGlyph = spriteGlyphTable[glyphIndex];
113-
114-
// We only update changes to the sprite position / glyph rect.
115-
if (spriteGlyph.glyphRect.x != sprite.rect.x || spriteGlyph.glyphRect.y != sprite.rect.y || spriteGlyph.glyphRect.width != sprite.rect.width || spriteGlyph.glyphRect.height != sprite.rect.height)
116-
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
117-
}
118137
}
119138

120139
// Update Sprite Character Table to replace unicode 0x0 by 0xFFFE
@@ -129,6 +148,7 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
129148
spriteAsset.SortGlyphTable();
130149
spriteAsset.UpdateLookupTables();
131150
TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);
151+
132152
}
133153

134154

@@ -365,7 +385,5 @@ private static List<TMP_Sprite> UpdateSpriteInfo(TMP_SpriteAsset spriteAsset)
365385

366386
return spriteAsset.spriteInfoList;
367387
}
368-
369-
370388
}
371389
}

Scripts/Editor/TMPro_ContextMenus.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ static void DuplicateMaterial(MenuCommand command)
5050
return;
5151
}
5252

53-
string assetPath = AssetDatabase.GetAssetPath(source_Mat).Split('.')[0];
53+
string assetPath = AssetDatabase.GetAssetPath(source_Mat).Split('.')[0];
5454

5555
if (assetPath.IndexOf("Assets/", System.StringComparison.InvariantCultureIgnoreCase) == -1)
5656
{
5757
Debug.LogWarning("Material Preset cannot be created from a material that is located outside the project.");
5858
return;
5959
}
60-
60+
6161
Material duplicate = new Material(source_Mat);
6262

6363
// Need to manually copy the shader keywords
@@ -241,15 +241,24 @@ static void PasteAtlas(MenuCommand command)
241241
{
242242
Material mat = command.context as Material;
243243

244+
if (mat == null)
245+
return;
246+
244247
if (m_copiedAtlasProperties != null)
245248
{
246249
Undo.RecordObject(mat, "Paste Texture");
247250

248251
ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
249-
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
250-
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
251-
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
252-
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
252+
253+
if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_MainTex))
254+
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
255+
256+
if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_GradientScale))
257+
{
258+
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
259+
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
260+
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
261+
}
253262
}
254263
else if (m_copiedTexture != null)
255264
{
@@ -294,7 +303,7 @@ static void ExtractAtlas(MenuCommand command)
294303
}
295304

296305
/// <summary>
297-
///
306+
///
298307
/// </summary>
299308
/// <param name="command"></param>
300309
[MenuItem("CONTEXT/TMP_FontAsset/Update Atlas Texture...", false, 2000)]
@@ -355,4 +364,4 @@ static void CreateFontAsset(MenuCommand command)
355364
}
356365
}
357366
}
358-
}
367+
}

Scripts/Runtime/TMP_InputField.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,18 +3717,16 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
37173717
if (m_TextViewport == null)
37183718
return;
37193719

3720-
Vector2 caretPosition = new Vector2(startPosition.x + m_TextComponent.rectTransform.localPosition.x + m_TextViewport.localPosition.x + transform.localPosition.x, startPosition.y + m_TextComponent.rectTransform.localPosition.y + m_TextViewport.localPosition.y + transform.localPosition.y);
3720+
Vector3 localPosition = transform.localPosition;
3721+
Vector3 textComponentLocalPosition = m_TextComponent.rectTransform.localPosition;
3722+
Vector3 textViewportLocalPosition = m_TextViewport.localPosition;
3723+
Rect textViewportRect = m_TextViewport.rect;
37213724

3722-
Rect viewportWSRect = new Rect(transform.localPosition.x + m_TextViewport.localPosition.x + m_TextViewport.rect.x, transform.localPosition.y + m_TextViewport.localPosition.y + m_TextViewport.rect.y, m_TextViewport.rect.width, m_TextViewport.rect.height);
3723-
//Rect textWSRect = new Rect(m_TextComponent.rectTransform.localPosition.x + m_TextComponent.rectTransform.rect.x, m_TextComponent.rectTransform.localPosition.y + m_TextComponent.rectTransform.rect.y, m_TextComponent.rectTransform.rect.width, m_TextComponent.rectTransform.rect.height);
3724-
3725-
//Debug.Log("Caret: " + caretPositionWS.ToString("f4") +
3726-
// "\nViewport: " + m_TextViewport.position.ToString("f4") + " Rect: " + viewportMinWS.ToString("f4") + " Max: " + viewportMaxWS.ToString("f4") +
3727-
// "\nText: " + m_TextComponent.rectTransform.position.ToString("f4") + textRectMinWS.ToString("f4") + " Max: " + textRectMaxWS.ToString("f4"));
3725+
Vector2 caretPosition = new Vector2(startPosition.x + textComponentLocalPosition.x + textViewportLocalPosition.x + localPosition.x, startPosition.y + textComponentLocalPosition.y + textViewportLocalPosition.y + localPosition.y);
3726+
Rect viewportWSRect = new Rect(localPosition.x + textViewportLocalPosition.x + textViewportRect.x, localPosition.y + textViewportLocalPosition.y + textViewportRect.y, textViewportRect.width, textViewportRect.height);
37283727

37293728
// Adjust the position of the RectTransform based on the caret position in the viewport.
3730-
float rightOffset = viewportWSRect.xMax - (caretPosition.x + m_TextComponent.margin.z);
3731-
//float rightOffset = viewportMaxWS.x - (caretPositionWS.x + m_TextComponent.margin.z);
3729+
float rightOffset = viewportWSRect.xMax - (caretPosition.x + m_TextComponent.margin.z + m_CaretWidth);
37323730
if (rightOffset < 0f)
37333731
{
37343732
if (!multiLine || (multiLine && isCharVisible))
@@ -3775,10 +3773,10 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
37753773
{
37763774
float anchoredPositionX = m_TextComponent.rectTransform.anchoredPosition.x;
37773775

3778-
float firstCharPosition = transform.localPosition.x + m_TextViewport.localPosition.x + m_TextComponent.rectTransform.localPosition.x + m_TextComponent.textInfo.characterInfo[0].origin - m_TextComponent.margin.x;
3779-
float lastCharPosition = transform.localPosition.x + m_TextViewport.localPosition.x + m_TextComponent.rectTransform.localPosition.x + m_TextComponent.textInfo.characterInfo[m_TextComponent.textInfo.characterCount - 1].origin + m_TextComponent.margin.z;
3776+
float firstCharPosition = localPosition.x + textViewportLocalPosition.x + textComponentLocalPosition.x + m_TextComponent.textInfo.characterInfo[0].origin - m_TextComponent.margin.x;
3777+
float lastCharPosition = localPosition.x + textViewportLocalPosition.x + textComponentLocalPosition.x + m_TextComponent.textInfo.characterInfo[m_TextComponent.textInfo.characterCount - 1].origin + m_TextComponent.margin.z + m_CaretWidth;
37803778

3781-
if (anchoredPositionX > 0.0001f)
3779+
if (anchoredPositionX > 0.0001f && firstCharPosition > viewportWSRect.xMin)
37823780
{
37833781
float offset = viewportWSRect.xMin - firstCharPosition;
37843782

@@ -3788,7 +3786,7 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
37883786
m_TextComponent.rectTransform.anchoredPosition += new Vector2(offset, 0);
37893787
AssignPositioningIfNeeded();
37903788
}
3791-
else if (anchoredPositionX < -0.0001f)
3789+
else if (anchoredPositionX < -0.0001f && lastCharPosition < viewportWSRect.xMax)
37923790
{
37933791
float offset = viewportWSRect.xMax - lastCharPosition;
37943792

Scripts/Runtime/TMP_Settings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ public static bool autoSizeTextContainer
200200
[SerializeField]
201201
private bool m_autoSizeTextContainer;
202202

203+
/// <summary>
204+
/// Disables InternalUpdate() calls when true. This can improve performance when the scale of the text object is static.
205+
/// </summary>
206+
public static bool isTextObjectScaleStatic
207+
{
208+
get { return instance.m_IsTextObjectScaleStatic; }
209+
set { instance.m_IsTextObjectScaleStatic = value; }
210+
}
211+
[SerializeField]
212+
private bool m_IsTextObjectScaleStatic;
213+
214+
203215
/// <summary>
204216
/// Returns the list of Fallback Fonts defined in the TMP Settings file.
205217
/// </summary>

0 commit comments

Comments
 (0)