Skip to content

Commit

Permalink
com.unity.textmeshpro@1.5.0-preview.12
Browse files Browse the repository at this point in the history
## [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
  • Loading branch information
Unity Technologies committed May 8, 2020
1 parent 45f7472 commit 6df08ea
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 164 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Changelog
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

## [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.5.0-preview.11] - 2020-04-22
## [2.1.0-preview.11]
## [3.0.0-preview.11]
Expand Down
4 changes: 4 additions & 0 deletions Scripts/Editor/TMP_SettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class Styles
public static readonly GUIContent textMeshProUiLabel = new GUIContent("TextMeshPro UI");
public static readonly GUIContent enableRaycastTarget = new GUIContent("Enable Raycast Target");
public static readonly GUIContent autoSizeContainerLabel = new GUIContent("Auto Size Text Container", "Set the size of the text container to match the text.");
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.");

public static readonly GUIContent textComponentDefaultSettingsLabel = new GUIContent("Text Component Default Settings");
public static readonly GUIContent defaultFontSize = new GUIContent("Default Font Size");
Expand Down Expand Up @@ -73,6 +74,7 @@ internal class Styles
SerializedProperty m_PropDefaultTextMeshProUITextContainerSize;
SerializedProperty m_PropAutoSizeTextContainer;
SerializedProperty m_PropEnableRaycastTarget;
SerializedProperty m_PropIsTextObjectScaleStatic;

SerializedProperty m_PropSpriteAsset;
SerializedProperty m_PropMissingSpriteCharacterUnicode;
Expand Down Expand Up @@ -120,6 +122,7 @@ public void OnEnable()
m_PropDefaultTextMeshProUITextContainerSize = serializedObject.FindProperty("m_defaultTextMeshProUITextContainerSize");
m_PropAutoSizeTextContainer = serializedObject.FindProperty("m_autoSizeTextContainer");
m_PropEnableRaycastTarget = serializedObject.FindProperty("m_EnableRaycastTarget");
m_PropIsTextObjectScaleStatic = serializedObject.FindProperty("m_IsTextObjectScaleStatic");

m_PropSpriteAsset = serializedObject.FindProperty("m_defaultSpriteAsset");
m_PropMissingSpriteCharacterUnicode = serializedObject.FindProperty("m_MissingCharacterSpriteUnicode");
Expand Down Expand Up @@ -223,6 +226,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(m_PropDefaultTextMeshProUITextContainerSize, Styles.textMeshProUiLabel);
EditorGUILayout.PropertyField(m_PropEnableRaycastTarget, Styles.enableRaycastTarget);
EditorGUILayout.PropertyField(m_PropAutoSizeTextContainer, Styles.autoSizeContainerLabel);
EditorGUILayout.PropertyField(m_PropIsTextObjectScaleStatic, Styles.isTextObjectScaleStaticLabel);
EditorGUI.indentLevel = 0;

EditorGUILayout.Space();
Expand Down
76 changes: 47 additions & 29 deletions Scripts/Editor/TMP_SpriteAssetMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace TMPro.EditorUtilities
{

public static class TMP_SpriteAssetMenu
{
// Add a Context Menu to the Sprite Asset Editor Panel to Create and Add a Default Material.
Expand Down Expand Up @@ -48,39 +47,70 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
if (string.IsNullOrEmpty(filePath))
return;

// Get all the Sprites sorted Left to Right / Top to Bottom
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();
// Get all the sprites defined in the sprite sheet texture referenced by this sprite asset.
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).ToArray();

// Return if sprite sheet texture does not have any sprites defined in it.
if (sprites.Length == 0)
{
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);
return;
}

List<TMP_SpriteGlyph> spriteGlyphTable = spriteAsset.spriteGlyphTable;

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

uint lastGlyphIndex = existingGlyphIndexes.Length > 0 ? existingGlyphIndexes.Last() : 0;
int elementIndex = 0;
for (uint i = 0; i < tempGlyphTable[tempGlyphTable.Count - 1].index; i++)
for (uint i = 0; i < lastGlyphIndex; i++)
{
uint currentElementIndex = tempGlyphTable[elementIndex].index;
uint existingGlyphIndex = existingGlyphIndexes[elementIndex];

if (i == currentElementIndex)
if (i == existingGlyphIndex)
elementIndex += 1;
else
availableGlyphIndexes.Add(i);
}

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

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

if (glyphIndex == -1)
if (spriteGlyph != null)
{
// Add new Sprite Glyph to the table
Sprite sprite = sprites[i];
// update existing sprite glyph
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)
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
}
else
{
TMP_SpriteCharacter spriteCharacter;

// Check if this sprite potentially exists under the same name in the sprite character table.
if (spriteAsset.spriteCharacterTable != null && spriteAsset.spriteCharacterTable.Count > 0)
{
spriteCharacter = spriteAsset.spriteCharacterTable.FirstOrDefault(x => x.name == sprite.name);
spriteGlyph = spriteCharacter != null ? spriteGlyphTable[(int)spriteCharacter.glyphIndex] : null;

TMP_SpriteGlyph spriteGlyph = new TMP_SpriteGlyph();
if (spriteGlyph != null)
{
// Update sprite reference and data
spriteGlyph.sprite = sprite;

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)
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
}
}

// Add new Sprite Glyph to the table
spriteGlyph = new TMP_SpriteGlyph();

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

spriteGlyphTable.Add(spriteGlyph);

TMP_SpriteCharacter spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
spriteCharacter = new TMP_SpriteCharacter(0xFFFE, spriteGlyph);
spriteCharacter.name = sprite.name;
spriteCharacter.scale = 1.0f;

spriteAsset.spriteCharacterTable.Add(spriteCharacter);
}
else
{
// Look for changes in existing Sprite Glyph
Sprite sprite = sprites[i];

TMP_SpriteGlyph spriteGlyph = spriteGlyphTable[glyphIndex];

// We only update changes to the sprite position / glyph rect.
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)
spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
}
}

// Update Sprite Character Table to replace unicode 0x0 by 0xFFFE
Expand All @@ -129,6 +148,7 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
spriteAsset.SortGlyphTable();
spriteAsset.UpdateLookupTables();
TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);

}


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

return spriteAsset.spriteInfoList;
}


}
}
25 changes: 17 additions & 8 deletions Scripts/Editor/TMPro_ContextMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ static void DuplicateMaterial(MenuCommand command)
return;
}

string assetPath = AssetDatabase.GetAssetPath(source_Mat).Split('.')[0];
string assetPath = AssetDatabase.GetAssetPath(source_Mat).Split('.')[0];

if (assetPath.IndexOf("Assets/", System.StringComparison.InvariantCultureIgnoreCase) == -1)
{
Debug.LogWarning("Material Preset cannot be created from a material that is located outside the project.");
return;
}

Material duplicate = new Material(source_Mat);

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

if (mat == null)
return;

if (m_copiedAtlasProperties != null)
{
Undo.RecordObject(mat, "Paste Texture");

ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));

if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_MainTex))
mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));

if (m_copiedAtlasProperties.HasProperty(ShaderUtilities.ID_GradientScale))
{
mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
}
}
else if (m_copiedTexture != null)
{
Expand Down Expand Up @@ -294,7 +303,7 @@ static void ExtractAtlas(MenuCommand command)
}

/// <summary>
///
///
/// </summary>
/// <param name="command"></param>
[MenuItem("CONTEXT/TMP_FontAsset/Update Atlas Texture...", false, 2000)]
Expand Down Expand Up @@ -355,4 +364,4 @@ static void CreateFontAsset(MenuCommand command)
}
}
}
}
}
24 changes: 11 additions & 13 deletions Scripts/Runtime/TMP_InputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3717,18 +3717,16 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
if (m_TextViewport == null)
return;

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);
Vector3 localPosition = transform.localPosition;
Vector3 textComponentLocalPosition = m_TextComponent.rectTransform.localPosition;
Vector3 textViewportLocalPosition = m_TextViewport.localPosition;
Rect textViewportRect = m_TextViewport.rect;

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);
//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);

//Debug.Log("Caret: " + caretPositionWS.ToString("f4") +
// "\nViewport: " + m_TextViewport.position.ToString("f4") + " Rect: " + viewportMinWS.ToString("f4") + " Max: " + viewportMaxWS.ToString("f4") +
// "\nText: " + m_TextComponent.rectTransform.position.ToString("f4") + textRectMinWS.ToString("f4") + " Max: " + textRectMaxWS.ToString("f4"));
Vector2 caretPosition = new Vector2(startPosition.x + textComponentLocalPosition.x + textViewportLocalPosition.x + localPosition.x, startPosition.y + textComponentLocalPosition.y + textViewportLocalPosition.y + localPosition.y);
Rect viewportWSRect = new Rect(localPosition.x + textViewportLocalPosition.x + textViewportRect.x, localPosition.y + textViewportLocalPosition.y + textViewportRect.y, textViewportRect.width, textViewportRect.height);

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

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

if (anchoredPositionX > 0.0001f)
if (anchoredPositionX > 0.0001f && firstCharPosition > viewportWSRect.xMin)
{
float offset = viewportWSRect.xMin - firstCharPosition;

Expand All @@ -3788,7 +3786,7 @@ private void AdjustRectTransformRelativeToViewport(Vector2 startPosition, float
m_TextComponent.rectTransform.anchoredPosition += new Vector2(offset, 0);
AssignPositioningIfNeeded();
}
else if (anchoredPositionX < -0.0001f)
else if (anchoredPositionX < -0.0001f && lastCharPosition < viewportWSRect.xMax)
{
float offset = viewportWSRect.xMax - lastCharPosition;

Expand Down
12 changes: 12 additions & 0 deletions Scripts/Runtime/TMP_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ public static bool autoSizeTextContainer
[SerializeField]
private bool m_autoSizeTextContainer;

/// <summary>
/// Disables InternalUpdate() calls when true. This can improve performance when the scale of the text object is static.
/// </summary>
public static bool isTextObjectScaleStatic
{
get { return instance.m_IsTextObjectScaleStatic; }
set { instance.m_IsTextObjectScaleStatic = value; }
}
[SerializeField]
private bool m_IsTextObjectScaleStatic;


/// <summary>
/// Returns the list of Fallback Fonts defined in the TMP Settings file.
/// </summary>
Expand Down
Loading

0 comments on commit 6df08ea

Please sign in to comment.