Skip to content

Commit 5152b17

Browse files
author
Unity Technologies
committed
com.unity.textmeshpro@1.5.0-preview.14
## [1.5.0-preview.14] - 2020-06-08 ## [2.1.0-preview.14] ## [3.0.0-preview.14] ### Changes - Fixed sprite character and sprite glyph scale not being reflected in the text layout. See [forum post](https://forum.unity.com/threads/glyph-scale-dont-change-line-height.898817/) for details. - Fixed potential null reference exception in the CrossFadeColor or CrossFadeAlpha functions. See [forum post](https://forum.unity.com/threads/version-1-5-0-2-1-0-3-0-0-preview-13-now-available-for-testing.753587/page-4#post-5885075) for details. - Minor improvements to the Sprite Asset Importer to improve allocations and address potential error encountered when creating multiple sprite assets. - TMP GUID Remapping Tool - Removed "UnityEditor.Animations.AnimatorController" from the exclusion search list. - Fixed potential culling issue when dynamically updating the content of child text objects of RectMask2D components. Case #1253625 - Fixed InvalidOperationException that could occur when changing text Overflow linked components via code. Case #1251283
1 parent 8622821 commit 5152b17

16 files changed

+363
-127
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
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.14] - 2020-06-08
5+
## [2.1.0-preview.14]
6+
## [3.0.0-preview.14]
7+
### Changes
8+
- Fixed sprite character and sprite glyph scale not being reflected in the text layout. See [forum post](https://forum.unity.com/threads/glyph-scale-dont-change-line-height.898817/) for details.
9+
- Fixed potential null reference exception in the CrossFadeColor or CrossFadeAlpha functions. See [forum post](https://forum.unity.com/threads/version-1-5-0-2-1-0-3-0-0-preview-13-now-available-for-testing.753587/page-4#post-5885075) for details.
10+
- Minor improvements to the Sprite Asset Importer to improve allocations and address potential error encountered when creating multiple sprite assets.
11+
- TMP GUID Remapping Tool - Removed "UnityEditor.Animations.AnimatorController" from the exclusion search list.
12+
- Fixed potential culling issue when dynamically updating the content of child text objects of RectMask2D components. Case #1253625
13+
- Fixed InvalidOperationException that could occur when changing text Overflow linked components via code. Case #1251283
14+
415
## [1.5.0-preview.13] - 2020-05-22
516
## [2.1.0-preview.13]
617
## [3.0.0-preview.13]

Scripts/Editor/TMP_PackageUtilities.cs

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static void ShowConverterWindow()
7272
typeof(Texture2D),
7373
typeof(Texture2DArray),
7474
typeof(Texture3D),
75-
typeof(UnityEditor.Animations.AnimatorController),
7675
typeof(UnityEditorInternal.AssemblyDefinitionAsset),
7776
typeof(UnityEngine.AI.NavMeshData),
7877
typeof(UnityEngine.Tilemaps.Tile),

Scripts/Editor/TMP_SpriteAssetImporter.cs

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23
using UnityEngine.TextCore;
34
using UnityEditor;
45
using System.IO;
@@ -28,19 +29,36 @@ public static void ShowFontAtlasCreatorWindow()
2829
TMP_SpriteAsset m_SpriteAsset;
2930
List<TMP_Sprite> m_SpriteInfoList = new List<TMP_Sprite>();
3031

31-
32+
/// <summary>
33+
///
34+
/// </summary>
3235
void OnEnable()
3336
{
3437
// Set Editor Window Size
3538
SetEditorWindowSize();
3639
}
3740

41+
/// <summary>
42+
///
43+
/// </summary>
3844
public void OnGUI()
3945
{
4046
DrawEditorPanel();
4147
}
4248

49+
/// <summary>
50+
///
51+
/// </summary>
52+
private void OnDisable()
53+
{
54+
// Clean up sprite asset object that may have been created and not saved.
55+
if (m_SpriteAsset != null && !EditorUtility.IsPersistent(m_SpriteAsset))
56+
DestroyImmediate(m_SpriteAsset);
57+
}
4358

59+
/// <summary>
60+
///
61+
/// </summary>
4462
void DrawEditorPanel()
4563
{
4664
// label
@@ -70,6 +88,10 @@ void DrawEditorPanel()
7088
{
7189
m_CreationFeedback = string.Empty;
7290

91+
// Clean up sprite asset object that may have been previously created.
92+
if (m_SpriteAsset != null && !EditorUtility.IsPersistent(m_SpriteAsset))
93+
DestroyImmediate(m_SpriteAsset);
94+
7395
// Read json data file
7496
if (m_JsonFile != null)
7597
{
@@ -94,9 +116,6 @@ void DrawEditorPanel()
94116
m_CreationFeedback = "<b>Import Results</b>\n--------------------\n";
95117
m_CreationFeedback += "<color=#C0ffff><b>" + spriteCount + "</b></color> Sprites were imported from file.";
96118

97-
if (m_SpriteAsset != null)
98-
DestroyImmediate(m_SpriteAsset);
99-
100119
// Create new Sprite Asset
101120
m_SpriteAsset = CreateInstance<TMP_SpriteAsset>();
102121

@@ -122,7 +141,7 @@ void DrawEditorPanel()
122141
GUILayout.Space(5);
123142
GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Height(60));
124143
{
125-
EditorGUILayout.LabelField(m_CreationFeedback, TMP_UIStyleManager.label);
144+
EditorGUILayout.TextArea(m_CreationFeedback, TMP_UIStyleManager.label);
126145
}
127146
GUILayout.EndVertical();
128147

@@ -140,7 +159,6 @@ void DrawEditorPanel()
140159
GUI.enabled = true;
141160
}
142161

143-
144162
/// <summary>
145163
///
146164
/// </summary>
@@ -175,7 +193,6 @@ private static void PopulateSpriteTables(TexturePacker_JsonArray.SpriteDataObjec
175193
}
176194
}
177195

178-
179196
/// <summary>
180197
///
181198
/// </summary>
@@ -210,7 +227,6 @@ void SaveSpriteAsset(string filePath)
210227
AddDefaultMaterial(m_SpriteAsset);
211228
}
212229

213-
214230
/// <summary>
215231
/// Create and add new default material to sprite asset.
216232
/// </summary>
@@ -226,7 +242,6 @@ static void AddDefaultMaterial(TMP_SpriteAsset spriteAsset)
226242
AssetDatabase.AddObjectToAsset(material, spriteAsset);
227243
}
228244

229-
230245
/// <summary>
231246
/// Limits the minimum size of the editor window.
232247
/// </summary>
@@ -238,6 +253,5 @@ void SetEditorWindowSize()
238253

239254
editorWindow.minSize = new Vector2(Mathf.Max(230, currentWindowSize.x), Mathf.Max(300, currentWindowSize.y));
240255
}
241-
242256
}
243257
}

Scripts/Runtime/TMP_Asset.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23

34
namespace TMPro
45
{
56

67
// Base class inherited by the various TextMeshPro Assets.
7-
[System.Serializable]
8-
public class TMP_Asset : ScriptableObject
8+
[Serializable]
9+
public abstract class TMP_Asset : ScriptableObject
910
{
1011
/// <summary>
1112
/// Instance ID of the TMP Asset

Scripts/Runtime/TMP_ColorGradient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum ColorMode
1111
FourCornersGradient
1212
}
1313

14-
[System.Serializable]
14+
[System.Serializable][ExcludeFromPresetAttribute]
1515
public class TMP_ColorGradient : ScriptableObject
1616
{
1717
public ColorMode colorMode = ColorMode.FourCornersGradient;

Scripts/Runtime/TMP_FontAsset.cs

+120-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum AtlasPopulationMode
2323
}
2424

2525

26-
[Serializable]
26+
[Serializable][ExcludeFromPresetAttribute]
2727
public class TMP_FontAsset : TMP_Asset
2828
{
2929
/// <summary>
@@ -524,6 +524,115 @@ public static TMP_FontAsset CreateFontAsset(Font font, int samplingPointSize, in
524524
}
525525

526526

527+
/*
528+
/// <summary>
529+
/// Create new font asset using default settings from path to source font file.
530+
/// </summary>
531+
/// <param name="fontFilePath">Path to source font file.</param>
532+
/// <returns></returns>
533+
public static TMP_FontAsset CreateFontAsset(string fontFilePath)
534+
{
535+
return CreateFontAsset(fontFilePath, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic);
536+
}
537+
538+
public static TMP_FontAsset CreateFontAsset(string fontFilePath, int samplingPointSize, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode = AtlasPopulationMode.Dynamic, bool enableMultiAtlasSupport = true)
539+
{
540+
// Initialize FontEngine
541+
FontEngine.InitializeFontEngine();
542+
543+
// Load Font Face
544+
if (FontEngine.LoadFontFace(fontFilePath, samplingPointSize) != FontEngineError.Success)
545+
{
546+
//Debug.LogWarning("Unable to load font face for [" + font.name + "]. Make sure \"Include Font Data\" is enabled in the Font Import Settings.", font);
547+
return null;
548+
}
549+
550+
// Create new font asset
551+
TMP_FontAsset fontAsset = ScriptableObject.CreateInstance<TMP_FontAsset>();
552+
553+
fontAsset.m_Version = "1.1.0";
554+
fontAsset.faceInfo = FontEngine.GetFaceInfo();
555+
556+
// Set font reference and GUID
557+
if (atlasPopulationMode == AtlasPopulationMode.Dynamic)
558+
fontAsset.sourceFontFile = font;
559+
560+
// Set persistent reference to source font file in the Editor only.
561+
#if UNITY_EDITOR
562+
string guid;
563+
long localID;
564+
565+
UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(font, out guid, out localID);
566+
fontAsset.m_SourceFontFileGUID = guid;
567+
fontAsset.m_SourceFontFile_EditorRef = font;
568+
#endif
569+
570+
fontAsset.atlasPopulationMode = atlasPopulationMode;
571+
572+
fontAsset.atlasWidth = atlasWidth;
573+
fontAsset.atlasHeight = atlasHeight;
574+
fontAsset.atlasPadding = atlasPadding;
575+
fontAsset.atlasRenderMode = renderMode;
576+
577+
// Initialize array for the font atlas textures.
578+
fontAsset.atlasTextures = new Texture2D[1];
579+
580+
// Create and add font atlas texture.
581+
Texture2D texture = new Texture2D(0, 0, TextureFormat.Alpha8, false);
582+
583+
//texture.name = assetName + " Atlas";
584+
fontAsset.atlasTextures[0] = texture;
585+
586+
fontAsset.isMultiAtlasTexturesEnabled = enableMultiAtlasSupport;
587+
588+
// Add free rectangle of the size of the texture.
589+
int packingModifier;
590+
if (((GlyphRasterModes)renderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP)
591+
{
592+
packingModifier = 0;
593+
594+
// Optimize by adding static ref to shader.
595+
Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileBitmap);
596+
597+
//tmp_material.name = texture.name + " Material";
598+
tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
599+
tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
600+
tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
601+
602+
fontAsset.material = tmp_material;
603+
}
604+
else
605+
{
606+
packingModifier = 1;
607+
608+
// Optimize by adding static ref to shader.
609+
Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileSDF);
610+
611+
//tmp_material.name = texture.name + " Material";
612+
tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
613+
tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
614+
tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
615+
616+
tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, atlasPadding + packingModifier);
617+
618+
tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
619+
tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
620+
621+
fontAsset.material = tmp_material;
622+
}
623+
624+
fontAsset.freeGlyphRects = new List<GlyphRect>(8) { new GlyphRect(0, 0, atlasWidth - packingModifier, atlasHeight - packingModifier) };
625+
fontAsset.usedGlyphRects = new List<GlyphRect>(8);
626+
627+
// TODO: Consider adding support for extracting glyph positioning data
628+
629+
fontAsset.ReadFontAssetDefinition();
630+
631+
return fontAsset;
632+
}
633+
*/
634+
635+
527636
void Awake()
528637
{
529638
//Debug.Log("TMP Font Asset [" + this.name + "] with Version #" + m_Version + " has been enabled!");
@@ -533,6 +642,13 @@ void Awake()
533642
UpgradeFontAsset();
534643
}
535644

645+
#if UNITY_EDITOR
646+
private void OnValidate()
647+
{
648+
if (m_CharacterLookupDictionary == null || m_GlyphLookupDictionary == null)
649+
ReadFontAssetDefinition();
650+
}
651+
#endif
536652

537653
public void ReadFontAssetDefinition()
538654
{
@@ -2722,8 +2838,9 @@ internal void UpdateFontAssetData()
27222838

27232839
//TMP_ResourceManager.RebuildFontAssetCache(instanceID);
27242840

2725-
// Add glyphs
2726-
TryAddCharacters(unicodeCharacters, true);
2841+
// Add existing glyphs and characters back in the font asset (if any)
2842+
if (unicodeCharacters.Length > 0)
2843+
TryAddCharacters(unicodeCharacters, true);
27272844

27282845
Profiler.EndSample();
27292846
}

Scripts/Runtime/TMP_ResourcesManager.cs

+25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@ public class TMP_ResourceManager
1414

1515
static TMP_ResourceManager() { }
1616

17+
// ======================================================
18+
// TEXT SETTINGS MANAGEMENT
19+
// ======================================================
20+
21+
private static TMP_Settings s_TextSettings;
22+
23+
internal static TMP_Settings GetTextSettings()
24+
{
25+
if (s_TextSettings == null)
26+
{
27+
// Try loading the TMP Settings from a Resources folder in the user project.
28+
s_TextSettings = Resources.Load<TMP_Settings>("TextSettings"); // ?? ScriptableObject.CreateInstance<TMP_Settings>();
29+
30+
#if UNITY_EDITOR
31+
if (s_TextSettings == null)
32+
{
33+
// Open TMP Resources Importer to enable the user to import the TMP Essential Resources and option TMP Examples & Extras
34+
TMP_PackageResourceImporterWindow.ShowPackageImporterWindow();
35+
}
36+
#endif
37+
}
38+
39+
return s_TextSettings;
40+
}
41+
1742
// ======================================================
1843
// FONT ASSET MANAGEMENT - Fields, Properties and Functions
1944
// ======================================================

Scripts/Runtime/TMP_SpriteAsset.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace TMPro
88
{
9-
9+
[ExcludeFromPresetAttribute]
1010
public class TMP_SpriteAsset : TMP_Asset
1111
{
1212
internal Dictionary<int, int> m_NameLookup;

Scripts/Runtime/TMP_StyleSheet.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
namespace TMPro
77
{
88

9-
[Serializable]
9+
[Serializable][ExcludeFromPresetAttribute]
1010
public class TMP_StyleSheet : ScriptableObject
1111
{
1212
/// <summary>
13-
///
13+
///
1414
/// </summary>
1515
internal List<TMP_Style> styles
1616
{
@@ -67,7 +67,7 @@ public void RefreshStyles()
6767
}
6868

6969
/// <summary>
70-
///
70+
///
7171
/// </summary>
7272
private void LoadStyleDictionaryInternal()
7373
{
@@ -80,7 +80,7 @@ private void LoadStyleDictionaryInternal()
8080
for (int i = 0; i < m_StyleList.Count; i++)
8181
{
8282
m_StyleList[i].RefreshStyle();
83-
83+
8484
if (!m_StyleLookupDictionary.ContainsKey(m_StyleList[i].hashCode))
8585
m_StyleLookupDictionary.Add(m_StyleList[i].hashCode, m_StyleList[i]);
8686
}
@@ -92,4 +92,4 @@ private void LoadStyleDictionaryInternal()
9292
}
9393
}
9494

95-
}
95+
}

0 commit comments

Comments
 (0)