Skip to content

Commit 2c60001

Browse files
author
Unity Technologies
committed
com.unity.textmeshpro@3.0.0-preview.12
## [3.0.0-preview.12] - 2020-05-09
1 parent 093fb53 commit 2c60001

17 files changed

+270
-164
lines changed

CHANGELOG.md

+15
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+
## [3.0.0-preview.12] - 2020-05-09
5+
## [2.1.0-preview.12]
6+
## [1.5.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
## [3.0.0-preview.11] - 2020-04-22
520
## [2.1.0-preview.11]
621
## [1.5.0-preview.11]

Scripts/Editor/TMP_SettingsEditor.cs

+4
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

+47-29
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.
@@ -60,39 +59,70 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
6059
if (string.IsNullOrEmpty(filePath))
6160
return;
6261

63-
// Get all the Sprites sorted Left to Right / Top to Bottom
64-
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();
62+
// Get all the sprites defined in the sprite sheet texture referenced by this sprite asset.
63+
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).ToArray();
64+
65+
// Return if sprite sheet texture does not have any sprites defined in it.
66+
if (sprites.Length == 0)
67+
{
68+
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);
69+
return;
70+
}
6571

6672
List<TMP_SpriteGlyph> spriteGlyphTable = spriteAsset.spriteGlyphTable;
6773

68-
// Finding available glyph indexes to insert new glyphs into.
69-
var tempGlyphTable = spriteGlyphTable.OrderBy(glyph => glyph.index).ToList();
74+
// Find available glpyh indexes
75+
uint[] existingGlyphIndexes = spriteGlyphTable.Select(x => x.index).ToArray();
7076
List<uint> availableGlyphIndexes = new List<uint>();
7177

78+
uint lastGlyphIndex = existingGlyphIndexes.Length > 0 ? existingGlyphIndexes.Last() : 0;
7279
int elementIndex = 0;
73-
for (uint i = 0; i < tempGlyphTable[tempGlyphTable.Count - 1].index; i++)
80+
for (uint i = 0; i < lastGlyphIndex; i++)
7481
{
75-
uint currentElementIndex = tempGlyphTable[elementIndex].index;
82+
uint existingGlyphIndex = existingGlyphIndexes[elementIndex];
7683

77-
if (i == currentElementIndex)
84+
if (i == existingGlyphIndex)
7885
elementIndex += 1;
7986
else
8087
availableGlyphIndexes.Add(i);
8188
}
8289

83-
// Iterate over each of the sprites in the texture to try to match them to existing sprites in the sprite asset.
90+
// Iterate over sprites contained in the updated sprite sheet to identify new and / or modified sprites.
8491
for (int i = 0; i < sprites.Length; i++)
8592
{
86-
int id = sprites[i].GetInstanceID();
93+
Sprite sprite = sprites[i];
8794

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

90-
if (glyphIndex == -1)
98+
if (spriteGlyph != null)
9199
{
92-
// Add new Sprite Glyph to the table
93-
Sprite sprite = sprites[i];
100+
// update existing sprite glyph
101+
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)
102+
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
103+
}
104+
else
105+
{
106+
TMP_SpriteCharacter spriteCharacter;
107+
108+
// Check if this sprite potentially exists under the same name in the sprite character table.
109+
if (spriteAsset.spriteCharacterTable != null && spriteAsset.spriteCharacterTable.Count > 0)
110+
{
111+
spriteCharacter = spriteAsset.spriteCharacterTable.FirstOrDefault(x => x.name == sprite.name);
112+
spriteGlyph = spriteCharacter != null ? spriteGlyphTable[(int)spriteCharacter.glyphIndex] : null;
94113

95-
TMP_SpriteGlyph spriteGlyph = new TMP_SpriteGlyph();
114+
if (spriteGlyph != null)
115+
{
116+
// Update sprite reference and data
117+
spriteGlyph.sprite = sprite;
118+
119+
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)
120+
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
121+
}
122+
}
123+
124+
// Add new Sprite Glyph to the table
125+
spriteGlyph = new TMP_SpriteGlyph();
96126

97127
// Get available glyph index
98128
if (availableGlyphIndexes.Count > 0)
@@ -110,23 +140,12 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
110140

111141
spriteGlyphTable.Add(spriteGlyph);
112142

113-
TMP_SpriteCharacter spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
143+
spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
114144
spriteCharacter.name = sprite.name;
115145
spriteCharacter.scale = 1.0f;
116146

117147
spriteAsset.spriteCharacterTable.Add(spriteCharacter);
118148
}
119-
else
120-
{
121-
// Look for changes in existing Sprite Glyph
122-
Sprite sprite = sprites[i];
123-
124-
TMP_SpriteGlyph spriteGlyph = spriteGlyphTable[glyphIndex];
125-
126-
// We only update changes to the sprite position / glyph rect.
127-
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)
128-
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
129-
}
130149
}
131150

132151
// Update Sprite Character Table to replace unicode 0x0 by 0xFFFE
@@ -141,6 +160,7 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
141160
spriteAsset.SortGlyphTable();
142161
spriteAsset.UpdateLookupTables();
143162
TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);
163+
144164
}
145165

146166

@@ -377,7 +397,5 @@ private static List<TMP_Sprite> UpdateSpriteInfo(TMP_SpriteAsset spriteAsset)
377397

378398
return spriteAsset.spriteInfoList;
379399
}
380-
381-
382400
}
383401
}

Scripts/Editor/TMPro_ContextMenus.cs

+17-8
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
@@ -264,15 +264,24 @@ static void PasteAtlas(MenuCommand command)
264264
{
265265
Material mat = command.context as Material;
266266

267+
if (mat == null)
268+
return;
269+
267270
if (m_copiedAtlasProperties != null)
268271
{
269272
Undo.RecordObject(mat, "Paste Texture");
270273

271274
ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
272-
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
273-
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
274-
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
275-
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
275+
276+
if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_MainTex))
277+
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
278+
279+
if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_GradientScale))
280+
{
281+
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
282+
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
283+
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
284+
}
276285
}
277286
else if (m_copiedTexture != null)
278287
{
@@ -317,7 +326,7 @@ static void ExtractAtlas(MenuCommand command)
317326
}
318327

319328
/// <summary>
320-
///
329+
///
321330
/// </summary>
322331
/// <param name="command"></param>
323332
[MenuItem("CONTEXT/TMP_FontAsset/Update Atlas Texture...", false, 2000)]
@@ -384,4 +393,4 @@ static void CreateFontAsset(MenuCommand command)
384393
}
385394
}
386395
}
387-
}
396+
}

Scripts/Runtime/TMP_InputField.cs

+11-13
Original file line numberDiff line numberDiff line change
@@ -3719,18 +3719,16 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
37193719
if (m_TextViewport == null)
37203720
return;
37213721

3722-
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);
3722+
Vector3 localPosition = transform.localPosition;
3723+
Vector3 textComponentLocalPosition = m_TextComponent.rectTransform.localPosition;
3724+
Vector3 textViewportLocalPosition = m_TextViewport.localPosition;
3725+
Rect textViewportRect = m_TextViewport.rect;
37233726

3724-
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);
3725-
//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);
3726-
3727-
//Debug.Log("Caret: " + caretPositionWS.ToString("f4") +
3728-
// "\nViewport: " + m_TextViewport.position.ToString("f4") + " Rect: " + viewportMinWS.ToString("f4") + " Max: " + viewportMaxWS.ToString("f4") +
3729-
// "\nText: " + m_TextComponent.rectTransform.position.ToString("f4") + textRectMinWS.ToString("f4") + " Max: " + textRectMaxWS.ToString("f4"));
3727+
Vector2 caretPosition = new Vector2(startPosition.x + textComponentLocalPosition.x + textViewportLocalPosition.x + localPosition.x, startPosition.y + textComponentLocalPosition.y + textViewportLocalPosition.y + localPosition.y);
3728+
Rect viewportWSRect = new Rect(localPosition.x + textViewportLocalPosition.x + textViewportRect.x, localPosition.y + textViewportLocalPosition.y + textViewportRect.y, textViewportRect.width, textViewportRect.height);
37303729

37313730
// Adjust the position of the RectTransform based on the caret position in the viewport.
3732-
float rightOffset = viewportWSRect.xMax - (caretPosition.x + m_TextComponent.margin.z);
3733-
//float rightOffset = viewportMaxWS.x - (caretPositionWS.x + m_TextComponent.margin.z);
3731+
float rightOffset = viewportWSRect.xMax - (caretPosition.x + m_TextComponent.margin.z + m_CaretWidth);
37343732
if (rightOffset < 0f)
37353733
{
37363734
if (!multiLine || (multiLine && isCharVisible))
@@ -3777,10 +3775,10 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
37773775
{
37783776
float anchoredPositionX = m_TextComponent.rectTransform.anchoredPosition.x;
37793777

3780-
float firstCharPosition = transform.localPosition.x + m_TextViewport.localPosition.x + m_TextComponent.rectTransform.localPosition.x + m_TextComponent.textInfo.characterInfo[0].origin - m_TextComponent.margin.x;
3781-
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;
3778+
float firstCharPosition = localPosition.x + textViewportLocalPosition.x + textComponentLocalPosition.x + m_TextComponent.textInfo.characterInfo[0].origin - m_TextComponent.margin.x;
3779+
float lastCharPosition = localPosition.x + textViewportLocalPosition.x + textComponentLocalPosition.x + m_TextComponent.textInfo.characterInfo[m_TextComponent.textInfo.characterCount - 1].origin + m_TextComponent.margin.z + m_CaretWidth;
37823780

3783-
if (anchoredPositionX > 0.0001f)
3781+
if (anchoredPositionX > 0.0001f && firstCharPosition > viewportWSRect.xMin)
37843782
{
37853783
float offset = viewportWSRect.xMin - firstCharPosition;
37863784

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

Scripts/Runtime/TMP_Settings.cs

+12
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)