Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [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
  • Loading branch information
Unity Technologies committed Jun 8, 2020
1 parent 8622821 commit 5152b17
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 127 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# 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.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.5.0-preview.13] - 2020-05-22
## [2.1.0-preview.13]
## [3.0.0-preview.13]
Expand Down
1 change: 0 additions & 1 deletion Scripts/Editor/TMP_PackageUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static void ShowConverterWindow()
typeof(Texture2D),
typeof(Texture2DArray),
typeof(Texture3D),
typeof(UnityEditor.Animations.AnimatorController),
typeof(UnityEditorInternal.AssemblyDefinitionAsset),
typeof(UnityEngine.AI.NavMeshData),
typeof(UnityEngine.Tilemaps.Tile),
Expand Down
36 changes: 25 additions & 11 deletions Scripts/Editor/TMP_SpriteAssetImporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;
using UnityEngine.TextCore;
using UnityEditor;
using System.IO;
Expand Down Expand Up @@ -28,19 +29,36 @@ public static void ShowFontAtlasCreatorWindow()
TMP_SpriteAsset m_SpriteAsset;
List<TMP_Sprite> m_SpriteInfoList = new List<TMP_Sprite>();


/// <summary>
///
/// </summary>
void OnEnable()
{
// Set Editor Window Size
SetEditorWindowSize();
}

/// <summary>
///
/// </summary>
public void OnGUI()
{
DrawEditorPanel();
}

/// <summary>
///
/// </summary>
private void OnDisable()
{
// Clean up sprite asset object that may have been created and not saved.
if (m_SpriteAsset != null && !EditorUtility.IsPersistent(m_SpriteAsset))
DestroyImmediate(m_SpriteAsset);
}

/// <summary>
///
/// </summary>
void DrawEditorPanel()
{
// label
Expand Down Expand Up @@ -70,6 +88,10 @@ void DrawEditorPanel()
{
m_CreationFeedback = string.Empty;

// Clean up sprite asset object that may have been previously created.
if (m_SpriteAsset != null && !EditorUtility.IsPersistent(m_SpriteAsset))
DestroyImmediate(m_SpriteAsset);

// Read json data file
if (m_JsonFile != null)
{
Expand All @@ -94,9 +116,6 @@ void DrawEditorPanel()
m_CreationFeedback = "<b>Import Results</b>\n--------------------\n";
m_CreationFeedback += "<color=#C0ffff><b>" + spriteCount + "</b></color> Sprites were imported from file.";

if (m_SpriteAsset != null)
DestroyImmediate(m_SpriteAsset);

// Create new Sprite Asset
m_SpriteAsset = CreateInstance<TMP_SpriteAsset>();

Expand All @@ -122,7 +141,7 @@ void DrawEditorPanel()
GUILayout.Space(5);
GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Height(60));
{
EditorGUILayout.LabelField(m_CreationFeedback, TMP_UIStyleManager.label);
EditorGUILayout.TextArea(m_CreationFeedback, TMP_UIStyleManager.label);
}
GUILayout.EndVertical();

Expand All @@ -140,7 +159,6 @@ void DrawEditorPanel()
GUI.enabled = true;
}


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -175,7 +193,6 @@ private static void PopulateSpriteTables(TexturePacker_JsonArray.SpriteDataObjec
}
}


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -210,7 +227,6 @@ void SaveSpriteAsset(string filePath)
AddDefaultMaterial(m_SpriteAsset);
}


/// <summary>
/// Create and add new default material to sprite asset.
/// </summary>
Expand All @@ -226,7 +242,6 @@ static void AddDefaultMaterial(TMP_SpriteAsset spriteAsset)
AssetDatabase.AddObjectToAsset(material, spriteAsset);
}


/// <summary>
/// Limits the minimum size of the editor window.
/// </summary>
Expand All @@ -238,6 +253,5 @@ void SetEditorWindowSize()

editorWindow.minSize = new Vector2(Mathf.Max(230, currentWindowSize.x), Mathf.Max(300, currentWindowSize.y));
}

}
}
7 changes: 4 additions & 3 deletions Scripts/Runtime/TMP_Asset.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using UnityEngine;
using System;
using UnityEngine;

namespace TMPro
{

// Base class inherited by the various TextMeshPro Assets.
[System.Serializable]
public class TMP_Asset : ScriptableObject
[Serializable]
public abstract class TMP_Asset : ScriptableObject
{
/// <summary>
/// Instance ID of the TMP Asset
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/TMP_ColorGradient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum ColorMode
FourCornersGradient
}

[System.Serializable]
[System.Serializable][ExcludeFromPresetAttribute]
public class TMP_ColorGradient : ScriptableObject
{
public ColorMode colorMode = ColorMode.FourCornersGradient;
Expand Down
123 changes: 120 additions & 3 deletions Scripts/Runtime/TMP_FontAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum AtlasPopulationMode
}


[Serializable]
[Serializable][ExcludeFromPresetAttribute]
public class TMP_FontAsset : TMP_Asset
{
/// <summary>
Expand Down Expand Up @@ -524,6 +524,115 @@ public static TMP_FontAsset CreateFontAsset(Font font, int samplingPointSize, in
}


/*
/// <summary>
/// Create new font asset using default settings from path to source font file.
/// </summary>
/// <param name="fontFilePath">Path to source font file.</param>
/// <returns></returns>
public static TMP_FontAsset CreateFontAsset(string fontFilePath)
{
return CreateFontAsset(fontFilePath, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic);
}
public static TMP_FontAsset CreateFontAsset(string fontFilePath, int samplingPointSize, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode = AtlasPopulationMode.Dynamic, bool enableMultiAtlasSupport = true)
{
// Initialize FontEngine
FontEngine.InitializeFontEngine();
// Load Font Face
if (FontEngine.LoadFontFace(fontFilePath, samplingPointSize) != FontEngineError.Success)
{
//Debug.LogWarning("Unable to load font face for [" + font.name + "]. Make sure \"Include Font Data\" is enabled in the Font Import Settings.", font);
return null;
}
// Create new font asset
TMP_FontAsset fontAsset = ScriptableObject.CreateInstance<TMP_FontAsset>();
fontAsset.m_Version = "1.1.0";
fontAsset.faceInfo = FontEngine.GetFaceInfo();
// Set font reference and GUID
if (atlasPopulationMode == AtlasPopulationMode.Dynamic)
fontAsset.sourceFontFile = font;
// Set persistent reference to source font file in the Editor only.
#if UNITY_EDITOR
string guid;
long localID;
UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(font, out guid, out localID);
fontAsset.m_SourceFontFileGUID = guid;
fontAsset.m_SourceFontFile_EditorRef = font;
#endif
fontAsset.atlasPopulationMode = atlasPopulationMode;
fontAsset.atlasWidth = atlasWidth;
fontAsset.atlasHeight = atlasHeight;
fontAsset.atlasPadding = atlasPadding;
fontAsset.atlasRenderMode = renderMode;
// Initialize array for the font atlas textures.
fontAsset.atlasTextures = new Texture2D[1];
// Create and add font atlas texture.
Texture2D texture = new Texture2D(0, 0, TextureFormat.Alpha8, false);
//texture.name = assetName + " Atlas";
fontAsset.atlasTextures[0] = texture;
fontAsset.isMultiAtlasTexturesEnabled = enableMultiAtlasSupport;
// Add free rectangle of the size of the texture.
int packingModifier;
if (((GlyphRasterModes)renderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP)
{
packingModifier = 0;
// Optimize by adding static ref to shader.
Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileBitmap);
//tmp_material.name = texture.name + " Material";
tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
fontAsset.material = tmp_material;
}
else
{
packingModifier = 1;
// Optimize by adding static ref to shader.
Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileSDF);
//tmp_material.name = texture.name + " Material";
tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth);
tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight);
tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, atlasPadding + packingModifier);
tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
fontAsset.material = tmp_material;
}
fontAsset.freeGlyphRects = new List<GlyphRect>(8) { new GlyphRect(0, 0, atlasWidth - packingModifier, atlasHeight - packingModifier) };
fontAsset.usedGlyphRects = new List<GlyphRect>(8);
// TODO: Consider adding support for extracting glyph positioning data
fontAsset.ReadFontAssetDefinition();
return fontAsset;
}
*/


void Awake()
{
//Debug.Log("TMP Font Asset [" + this.name + "] with Version #" + m_Version + " has been enabled!");
Expand All @@ -533,6 +642,13 @@ void Awake()
UpgradeFontAsset();
}

#if UNITY_EDITOR
private void OnValidate()
{
if (m_CharacterLookupDictionary == null || m_GlyphLookupDictionary == null)
ReadFontAssetDefinition();
}
#endif

public void ReadFontAssetDefinition()
{
Expand Down Expand Up @@ -2722,8 +2838,9 @@ internal void UpdateFontAssetData()

//TMP_ResourceManager.RebuildFontAssetCache(instanceID);

// Add glyphs
TryAddCharacters(unicodeCharacters, true);
// Add existing glyphs and characters back in the font asset (if any)
if (unicodeCharacters.Length > 0)
TryAddCharacters(unicodeCharacters, true);

Profiler.EndSample();
}
Expand Down
25 changes: 25 additions & 0 deletions Scripts/Runtime/TMP_ResourcesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ public class TMP_ResourceManager

static TMP_ResourceManager() { }

// ======================================================
// TEXT SETTINGS MANAGEMENT
// ======================================================

private static TMP_Settings s_TextSettings;

internal static TMP_Settings GetTextSettings()
{
if (s_TextSettings == null)
{
// Try loading the TMP Settings from a Resources folder in the user project.
s_TextSettings = Resources.Load<TMP_Settings>("TextSettings"); // ?? ScriptableObject.CreateInstance<TMP_Settings>();

#if UNITY_EDITOR
if (s_TextSettings == null)
{
// Open TMP Resources Importer to enable the user to import the TMP Essential Resources and option TMP Examples & Extras
TMP_PackageResourceImporterWindow.ShowPackageImporterWindow();
}
#endif
}

return s_TextSettings;
}

// ======================================================
// FONT ASSET MANAGEMENT - Fields, Properties and Functions
// ======================================================
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/TMP_SpriteAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TMPro
{

[ExcludeFromPresetAttribute]
public class TMP_SpriteAsset : TMP_Asset
{
internal Dictionary<int, int> m_NameLookup;
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Runtime/TMP_StyleSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
namespace TMPro
{

[Serializable]
[Serializable][ExcludeFromPresetAttribute]
public class TMP_StyleSheet : ScriptableObject
{
/// <summary>
///
///
/// </summary>
internal List<TMP_Style> styles
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public void RefreshStyles()
}

/// <summary>
///
///
/// </summary>
private void LoadStyleDictionaryInternal()
{
Expand All @@ -80,7 +80,7 @@ private void LoadStyleDictionaryInternal()
for (int i = 0; i < m_StyleList.Count; i++)
{
m_StyleList[i].RefreshStyle();

if (!m_StyleLookupDictionary.ContainsKey(m_StyleList[i].hashCode))
m_StyleLookupDictionary.Add(m_StyleList[i].hashCode, m_StyleList[i]);
}
Expand All @@ -92,4 +92,4 @@ private void LoadStyleDictionaryInternal()
}
}

}
}
Loading

0 comments on commit 5152b17

Please sign in to comment.