diff --git a/CHANGELOG.md b/CHANGELOG.md
index b416639..56a9399 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,23 @@
# 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.2.3] - 2018-05-29
+### Changes
+- Added new bitmap shader with support for Custom Font Atlas texture. This shader also includes a new property "Padding" to provide control over the geometry padding to closely fit a modified / custom font atlas texture.
+- Fixed an issue with ForceMeshUpdate(bool ignoreActiveState) not being handled correctly.
+- Cleaned up memory allocations from repeated use of the Font Asset Creator.
+- Sprites are now scaled based on the current font instead of the primary font asset assigned to the text object.
+- It is now possible to recall the most recent settings used when creating a font asset in the Font Asset Creator.
+- Newly created font assets now contain the settings used when they were last created. This will make the process of updating / regenerating font assets much easier.
+- New context menu "Update Font Asset" was added to the Font Asset inspector which will open the Font Asset Creator with the most recently used settings for that font asset.
+- New Context Menu "Create Font Asset" was added to the Font inspector panel which will open the Font Asset Creator with this source font file already selected.
+- Fixed 3 compiler warnings that would appear when using .Net 4.x.
+- Modified the TMP Settings to place the Missing Glyph options in their own section.
+- Renamed a symbol used for internal debugging to avoid potential conflicts with other user project defines.
+- TMP Sprite Importer "Create Sprite Asset" and "Save Sprite Asset" options are disabled unless a Sprite Data Source, Import Format and Sprite Texture Atlas are provided.
+- Improved the performance of the Project Files GUID Remapping tool.
+- Users will now be prompted to import the TMP Essential Resources when using the Font Asset Creator if such resources have not already been imported.
+
## [1.2.2] - 2018-03-28
### Changes
- Calling SetAllDirty() on a TMP text component will now force a regeneration of the text object including re-parsing of the text.
diff --git a/Package Resources/TMP Essential Resources.unitypackage b/Package Resources/TMP Essential Resources.unitypackage
index 22f6d8a..f548dba 100644
Binary files a/Package Resources/TMP Essential Resources.unitypackage and b/Package Resources/TMP Essential Resources.unitypackage differ
diff --git a/Package Resources/TMP Examples & Extras.unitypackage b/Package Resources/TMP Examples & Extras.unitypackage
index 7f49f15..d52a277 100644
Binary files a/Package Resources/TMP Examples & Extras.unitypackage and b/Package Resources/TMP Examples & Extras.unitypackage differ
diff --git a/PackageConversionData_Assets.json b/PackageConversionData_Assets.json
new file mode 100644
index 0000000..f07aa23
--- /dev/null
+++ b/PackageConversionData_Assets.json
@@ -0,0 +1,184 @@
+{
+ "assetRecords": [
+ {
+ "referencedResource": "TMP_FontAsset.cs",
+ "target": "guid: 74dfce233ddb29b4294c3e23c1d3650d",
+ "replacement": "guid: 71c1514a6bd24e1e882cebbe1904ce04"
+ },
+ {
+ "referencedResource": "TMP_FontAsset.cs",
+ "target": "fileID: -667331979, guid: 89f0137620f6af44b9ba852b4190e64e",
+ "replacement": "fileID: 11500000, guid: 71c1514a6bd24e1e882cebbe1904ce04"
+ },
+ {
+ "referencedResource": "Anton SDF.asset",
+ "target": "guid: f76ef802b8b940c46a31f9027f2b0158",
+ "replacement": "guid: 8a89fa14b10d46a99122fd4f73fca9a2"
+ },
+ {
+ "referencedResource": "Bangers SDF.asset",
+ "target": "guid: 808aa8f1ab804104aa7d0c337a6c1481",
+ "replacement": "guid: 125cb55b44b24c4393181402bc6200e6"
+ },
+ {
+ "referencedResource": "Electronic Highway Sign SDF.asset",
+ "target": "guid: 163292f6f226d954593d45b079f8aae0",
+ "replacement": "guid: dc36b3fdc14f47ebb36fd484a67e268a"
+ },
+ {
+ "referencedResource": "Oswald Bold SDF.asset",
+ "target": "guid: 09641b029dfa78843902b548a9de7553",
+ "replacement": "guid: 0161d805a3764c089bef00bfe00793f5"
+ },
+ {
+ "referencedResource": "Roboto-Bold SDF.asset",
+ "target": "guid: d62a573c923f5cb47b8ff65261033b90",
+ "replacement": "guid: 5302535af1044152a457ed104f1f4b91"
+ },
+ {
+ "referencedResource": "LiberationSans SDF.asset",
+ "target": "guid: 715b80e429c437e40867928a4e1fc975",
+ "replacement": "guid: 8f586378b4e144a9851e7b34d9b748ee"
+ },
+ {
+ "referencedResource": "TMP_Bitmap.shader",
+ "target": "guid: edfcf888cd11d9245b91d2883049a57e",
+ "replacement": "guid: 128e987d567d4e2c824d754223b3f3b0"
+ },
+ {
+ "referencedResource": "TMP_Bitmap-Mobile.shader",
+ "target": "guid: d1cf17907700cb647aa3ea423ba38f2e",
+ "replacement": "guid: 1e3b057af24249748ff873be7fafee47"
+ },
+ {
+ "referencedResource": "TMP_SDF.shader",
+ "target": "guid: dca26082f9cb439469295791d9f76fe5",
+ "replacement": "guid: 68e6db2ebdc24f95958faec2be5558d6"
+ },
+ {
+ "referencedResource": "TMP_SDF Overlay.shader",
+ "target": "guid: 4a7755d6b5b67874f89c85f56f95fe97",
+ "replacement": "guid: dd89cf5b9246416f84610a006f916af7"
+ },
+ {
+ "referencedResource": "TMP_SDF-Mobile.shader",
+ "target": "guid: cafd18099dfc0114896e0a8b277b81b6",
+ "replacement": "guid: fe393ace9b354375a9cb14cdbbc28be4"
+ },
+ {
+ "referencedResource": "TMP_SDF-Mobile Masking.shader",
+ "target": "guid: afc255f7c2be52e41973a3d10a2e632d",
+ "replacement": "guid: bc1ede39bf3643ee8e493720e4259791"
+ },
+ {
+ "referencedResource": "TMP_SDF-Mobile Overlay.shader",
+ "target": "guid: 9ecb3fe313cb5f7478141eba4a2d54ed",
+ "replacement": "guid: a02a7d8c237544f1962732b55a9aebf1"
+ },
+ {
+ "referencedResource": "TMP_SDF-Surface.shader",
+ "target": "guid: 8e6b9842dbb1a5a4887378afab854e63",
+ "replacement": "guid: f7ada0af4f174f0694ca6a487b8f543d"
+ },
+ {
+ "referencedResource": "TMP_SDF-Surface-Mobile.shader",
+ "target": "guid: 3c2ea7753c1425145a74d106ec1cd852",
+ "replacement": "guid: 85187c2149c549c5b33f0cdb02836b17"
+ },
+ {
+ "referencedResource": "TMP_Sprite.shader",
+ "target": "guid: 3a1c68c8292caf046bd21158886c5e40",
+ "replacement": "guid: cf81c85f95fe47e1a27f6ae460cf182c"
+ },
+ {
+ "referencedResource": "TMP_ColorGradient.cs",
+ "target": "guid: e90e18dd4a044ff4394833216e6bf4d2",
+ "replacement": "guid: 54d21f6ece3b46479f0c328f8c6007e0"
+ },
+ {
+ "referencedResource": "TMP_ColorGradient.cs",
+ "target": "fileID: 2108210716, guid: 89f0137620f6af44b9ba852b4190e64e",
+ "replacement": "fileID: 11500000, guid: 54d21f6ece3b46479f0c328f8c6007e0"
+ },
+ {
+ "referencedResource": "TMP_Settings.cs",
+ "target": "guid: aafc3c7b9e915d64e8ec3d2c88b3a231",
+ "replacement": "guid: 2705215ac5b84b70bacc50632be6e391"
+ },
+ {
+ "referencedResource": "TMP_Settings.cs",
+ "target": "fileID: -395462249, guid: 89f0137620f6af44b9ba852b4190e64e",
+ "replacement": "fileID: 11500000, guid: 2705215ac5b84b70bacc50632be6e391"
+ },
+ {
+ "referencedResource": "TMP Settings.asset",
+ "target": "guid: 69ed5bac41eebaa4c97e9d2a4168c54f",
+ "replacement": "guid: 3f5b5dff67a942289a9defa416b206f3"
+ },
+ {
+ "referencedResource": "LineBreaking Following Characters.txt",
+ "target": "guid: 312ba5b9e90627940866e19549a788cf",
+ "replacement": "guid: fade42e8bc714b018fac513c043d323b"
+ },
+ {
+ "referencedResource": "LineBreaking Leading Characters.txt",
+ "target": "guid: 8d713940fcbede142ae4a33ea0062b33",
+ "replacement": "guid: d82c1b31c7e74239bff1220585707d2b"
+ },
+ {
+ "referencedResource": "TMP_StyleSheet.cs",
+ "target": "guid: 13259b4ce497b194eb52a33d8eda0bdc",
+ "replacement": "guid: ab2114bdc8544297b417dfefe9f1e410"
+ },
+ {
+ "referencedResource": "TMP_StyleSheet.cs",
+ "target": "fileID: -1936749209, guid: 89f0137620f6af44b9ba852b4190e64e",
+ "replacement": "fileID: 11500000, guid: ab2114bdc8544297b417dfefe9f1e410"
+ },
+ {
+ "referencedResource": "TMP Default Style Sheet.asset",
+ "target": "guid: 54d1085f9a2fdea4587fcfc7dddcd4bc",
+ "replacement": "guid: f952c082cb03451daed3ee968ac6c63e"
+ },
+ {
+ "referencedResource": "TMP_SpriteAsset.cs",
+ "target": "guid: 90940d439ca0ef746af0b48419b92d2e",
+ "replacement": "guid: 84a92b25f83d49b9bc132d206b370281"
+ },
+ {
+ "referencedResource": "TMP_SpriteAsset.cs",
+ "target": "fileID: 2019389346, guid: 89f0137620f6af44b9ba852b4190e64e",
+ "replacement": "fileID: 11500000, guid: 84a92b25f83d49b9bc132d206b370281"
+ },
+ {
+ "referencedResource": "Default Sprite Asset.asset",
+ "target": "guid: 273ca6c80b4b5d746b5e548f532bffd8",
+ "replacement": "guid: fbef3c704dce48f08a44612d6c856c8d"
+ },
+ {
+ "referencedResource": "Default Sprite Asset.png",
+ "target": "guid: 5b32c2d36abe44540bed74c1f787033b",
+ "replacement": "guid: a0fc465d6cf04254a2938578735e2383"
+ },
+ {
+ "referencedResource": "EmojiOne.asset",
+ "target": "guid: 9a952e2781ef26940ae089f1053ef4ef",
+ "replacement": "guid: c41005c129ba4d66911b75229fd70b45"
+ },
+ {
+ "referencedResource": "EmojiOne.png",
+ "target": "guid: 6ec706981a919c3489f0b061a40054e2",
+ "replacement": "guid: dffef66376be4fa480fb02b19edbe903"
+ },
+ {
+ "referencedResource": "DropCap Numbers.asset",
+ "target": "guid: c4fd2a959a50b584b92dedfefec1ffda",
+ "replacement": "guid: 14aa93acbb234d16aaef0e8b46814db6"
+ },
+ {
+ "referencedResource": "DropCap Numbers.psd",
+ "target": "guid: 28b41fef228d6814f90e541deaf9f262",
+ "replacement": "guid: fd09957580ac4326916010f1f260975b"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/PackageConversionData_Assets.json.meta b/PackageConversionData_Assets.json.meta
new file mode 100644
index 0000000..4ef8dd6
--- /dev/null
+++ b/PackageConversionData_Assets.json.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: c7e0809b02755e24f8133b643439733b
+TextScriptImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Scripts/Editor/TMP_BitmapShaderGUI.cs b/Scripts/Editor/TMP_BitmapShaderGUI.cs
index 814b289..6e93105 100644
--- a/Scripts/Editor/TMP_BitmapShaderGUI.cs
+++ b/Scripts/Editor/TMP_BitmapShaderGUI.cs
@@ -44,6 +44,12 @@ void DoDebugPanel()
DoTexture2D("_MainTex", "Font Atlas");
if (material.HasProperty(ShaderUtilities.ID_VertexOffsetX))
{
+ if (material.HasProperty(ShaderUtilities.ID_Padding))
+ {
+ DoEmptyLine();
+ DoFloat("_Padding", "Padding");
+ }
+
DoEmptyLine();
DoFloat("_VertexOffsetX", "Offset X");
DoFloat("_VertexOffsetY", "Offset Y");
diff --git a/Scripts/Editor/TMP_FontAssetEditor.cs b/Scripts/Editor/TMP_FontAssetEditor.cs
index 64f6ca6..42150b7 100644
--- a/Scripts/Editor/TMP_FontAssetEditor.cs
+++ b/Scripts/Editor/TMP_FontAssetEditor.cs
@@ -175,7 +175,19 @@ public override void OnInspectorGUI()
serializedObject.Update();
- GUILayout.Label("TextMesh Pro! Font Asset", TMP_UIStyleManager.Section_Label);
+ // TextMeshPro Font Info Panel
+ Rect rect = EditorGUILayout.GetControlRect(true, 26f);
+ GUI.Label(rect, "TextMesh Pro! Font Asset", TMP_UIStyleManager.Section_Label);
+
+ rect.x = rect.width - 125;
+ rect.y += 2;
+ rect.width = 130f;
+ rect.height = 20f;
+
+ if (GUI.Button(rect, "Update Atlas Texture"))
+ {
+ TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(target as TMP_FontAsset);
+ }
// TextMeshPro Font Info Panel
GUILayout.Label("Face Info", TMP_UIStyleManager.Section_Label);
diff --git a/Scripts/Editor/TMP_PackageUtilities.cs b/Scripts/Editor/TMP_PackageUtilities.cs
index 7be36eb..7cb5e02 100644
--- a/Scripts/Editor/TMP_PackageUtilities.cs
+++ b/Scripts/Editor/TMP_PackageUtilities.cs
@@ -8,10 +8,33 @@
namespace TMPro
{
+ ///
+ /// Data structure containing the target and replacement fileIDs and GUIDs which will require remapping from previous version of TextMesh Pro to the new TextMesh Pro UPM package.
+ ///
+ [System.Serializable]
+ struct AssetConversionRecord
+ {
+ public string referencedResource;
+ public string target;
+ public string replacement;
+ }
+
+
+ ///
+ /// Data structure containing a list of target and replacement fileID and GUID requiring remapping from previous versions of TextMesh Pro to the new TextMesh Pro UPM package.
+ /// This data structure is populated with the data contained in the PackageConversionData.json file included in the package.
+ ///
+ [System.Serializable]
+ class AssetConversionData
+ {
+ public List assetRecords;
+ }
+
+
public class TMP_ProjectConversionUtility : EditorWindow
{
// Create Sprite Asset Editor Window
- [MenuItem("Window/TextMeshPro/Project Files GUID Remapping Tool", false, 2055)]
+ [MenuItem("Window/TextMeshPro/Project Files GUID Remapping Tool", false, 2100)]
static void ShowConverterWindow()
{
var window = GetWindow();
@@ -19,27 +42,6 @@ static void ShowConverterWindow()
window.Focus();
}
- ///
- /// Data structure containing the target and replacement fileIDs and GUIDs which will require remapping from previous version of TextMesh Pro to the new TextMesh Pro UPM package.
- ///
- [System.Serializable]
- private struct AssetConversionRecord
- {
- public string referencedResource;
- public string target;
- public string replacement;
- }
-
- ///
- /// Data structure containing a list of target and replacement fileID and GUID requiring remapping from previous versions of TextMesh Pro to the new TextMesh Pro UPM package.
- /// This data structure is populated with the data contained in the PackageConversionData.json file included in the package.
- ///
- [System.Serializable]
- #pragma warning disable 0649
- private class AssetConversionData
- {
- public List assetRecords;
- }
///
///
@@ -55,6 +57,8 @@ struct AssetModificationRecord
private static string m_ProjectScanResults = string.Empty;
private static Vector2 m_ProjectScanResultScrollPosition;
private static float m_ProgressPercentage = 0;
+ private static int m_ScanningTotalFiles;
+ private static int m_ScanningCurrentFileIndex;
private static List m_ModifiedAssetList = new List();
@@ -100,7 +104,7 @@ void OnGUI()
// Display progress bar
Rect rect = GUILayoutUtility.GetRect(0f, 20f, GUILayout.ExpandWidth(true));
- EditorGUI.ProgressBar(rect, m_ProgressPercentage, "Scan Progress");
+ EditorGUI.ProgressBar(rect, m_ProgressPercentage, "Scan Progress (" + m_ScanningCurrentFileIndex + "/" + m_ScanningTotalFiles + ")");
GUILayout.Space(5);
// Creation Feedback
@@ -168,21 +172,26 @@ private IEnumerator ScanProjectFiles()
// Read Conversion Data from Json file.
AssetConversionData conversionData = JsonUtility.FromJson(File.ReadAllText(packageFullPath + "/PackageConversionData.json"));
+ AssetConversionData conversionData_Assets = JsonUtility.FromJson(File.ReadAllText(packageFullPath + "/PackageConversionData_Assets.json"));
// Get list of GUIDs for assets that might contain references to previous GUIDs that require updating.
string[] projectGUIDs = AssetDatabase.FindAssets("t:Object");
+ m_ScanningTotalFiles = projectGUIDs.Length;
// Iterate through projectGUIDs to search project assets of the types likely to reference GUIDs and FileIDs used by previous versions of TextMesh Pro.
for (int i = 0; i < projectGUIDs.Length; i++)
{
- // Could add a progress bar for this process
+ m_ScanningCurrentFileIndex = i + 1;
string guid = projectGUIDs[i];
string assetFilePath = AssetDatabase.GUIDToAssetPath(guid);
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetFilePath);
// Filter out asset types that we can't read or have not interest in searching.
- if (assetType == typeof(DefaultAsset) || assetType == typeof(MonoScript) || assetType == typeof(Texture2D) || assetType == typeof(TextAsset) || assetType == typeof(Shader))
+ if (assetType == typeof(DefaultAsset) || assetType == typeof(MonoScript) || assetType == typeof(Texture2D) ||
+ assetType == typeof(TextAsset) || assetType == typeof(Shader) || assetType == typeof(Font) || assetType == typeof(UnityEditorInternal.AssemblyDefinitionAsset) ||
+ assetType == typeof(GUISkin) || assetType == typeof(PhysicsMaterial2D) || assetType == typeof(UnityEngine.U2D.SpriteAtlas) || assetType == typeof(UnityEngine.Tilemaps.Tile) ||
+ assetType == typeof(AudioClip) || assetType == typeof(ComputeShader) || assetType == typeof(UnityEditor.Animations.AnimatorController))
continue;
// Read the asset data file
@@ -201,15 +210,33 @@ private IEnumerator ScanProjectFiles()
bool hasFileChanged = false;
- foreach (AssetConversionRecord record in conversionData.assetRecords)
+ // Special handling / optimization if assetType is null
+ if (assetType == null)
{
- if (assetDataFile.Contains(record.target))
+ foreach (AssetConversionRecord record in conversionData_Assets.assetRecords)
{
- hasFileChanged = true;
+ if (assetDataFile.Contains(record.target))
+ {
+ hasFileChanged = true;
- assetDataFile = assetDataFile.Replace(record.target, record.replacement);
+ assetDataFile = assetDataFile.Replace(record.target, record.replacement);
- //Debug.Log("Replacing Reference to [" + record.referencedResource + "] using [" + record.target + "] with [" + record.replacement + "] in asset file: [" + assetFilePath + "].");
+ //Debug.Log("Replacing Reference to [" + record.referencedResource + "] using [" + record.target + "] with [" + record.replacement + "] in asset file: [" + assetFilePath + "].");
+ }
+ }
+ }
+ else
+ {
+ foreach (AssetConversionRecord record in conversionData.assetRecords)
+ {
+ if (assetDataFile.Contains(record.target))
+ {
+ hasFileChanged = true;
+
+ assetDataFile = assetDataFile.Replace(record.target, record.replacement);
+
+ //Debug.Log("Replacing Reference to [" + record.referencedResource + "] using [" + record.target + "] with [" + record.replacement + "] in asset file: [" + assetFilePath + "].");
+ }
}
}
@@ -785,25 +812,5 @@ private static void RestoreProjectSerializationAndSourceControlModes()
EditorSettings.externalVersionControl = m_ProjectExternalVersionControl;
}
-
- ///
- ///
- ///
- [System.Serializable]
- private struct AssetConversionRecord
- {
- public string referencedResource;
- public string target;
- public string replacement;
- }
-
- ///
- ///
- ///
- [System.Serializable]
- private class AssetConversionData
- {
- public List assetRecords;
- }
}
}
diff --git a/Scripts/Editor/TMP_SettingsEditor.cs b/Scripts/Editor/TMP_SettingsEditor.cs
index a522d0d..d6c7043 100644
--- a/Scripts/Editor/TMP_SettingsEditor.cs
+++ b/Scripts/Editor/TMP_SettingsEditor.cs
@@ -139,6 +139,19 @@ public override void OnInspectorGUI()
EditorGUILayout.EndVertical();
+ // MISSING GLYPH
+ EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G);
+ EditorGUIUtility.labelWidth = 135;
+ GUILayout.Label("Missing Glyph", TMP_UIStyleManager.Label);
+ GUILayout.Label("Define which glyph will be displayed in the event a requested glyph is missing from the specified font asset.", TMP_UIStyleManager.Label);
+ GUILayout.Space(5f);
+ EditorGUILayout.PropertyField(prop_MissingGlyphCharacter, new GUIContent("Missing Glyph Repl."), GUILayout.Width(180));
+ GUILayout.Space(10f);
+ GUILayout.Label("Disable warnings for missing glyphs on text objects.", TMP_UIStyleManager.Label);
+ EditorGUILayout.PropertyField(prop_WarningsDisabled, new GUIContent("Disable warnings"));
+ EditorGUILayout.EndVertical();
+
+
// TEXT OBJECT DEFAULT PROPERTIES
EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G);
GUILayout.Label("New Text Object Default Settings", TMP_UIStyleManager.Label);
@@ -170,25 +183,18 @@ public override void OnInspectorGUI()
EditorGUIUtility.labelWidth = 150;
EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(prop_WordWrapping); //, GUILayout.MaxWidth(200));
+ EditorGUILayout.PropertyField(prop_WordWrapping);
EditorGUILayout.PropertyField(prop_Kerning);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(prop_ExtraPadding); //, GUILayout.MaxWidth(200));
+ EditorGUILayout.PropertyField(prop_ExtraPadding);
EditorGUILayout.PropertyField(prop_TintAllSprites);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(prop_ParseEscapeCharacters, new GUIContent("Parse Escape Sequence")); //, GUILayout.MaxWidth(200));
- EditorGUIUtility.fieldWidth = 10;
- EditorGUILayout.PropertyField(prop_MissingGlyphCharacter, new GUIContent("Missing Glyph Repl."));
+ EditorGUILayout.PropertyField(prop_ParseEscapeCharacters, new GUIContent("Parse Escape Sequence"));
EditorGUILayout.EndHorizontal();
-
- EditorGUIUtility.labelWidth = 135;
- GUILayout.Space(10f);
- GUILayout.Label("Disable warnings for missing glyphs on text objects.", TMP_UIStyleManager.Label);
- EditorGUILayout.PropertyField(prop_WarningsDisabled, new GUIContent("Disable warnings"));
EditorGUILayout.EndVertical();
diff --git a/Scripts/Editor/TMP_SpriteAssetImporter.cs b/Scripts/Editor/TMP_SpriteAssetImporter.cs
index 7564b24..2a6b1ea 100644
--- a/Scripts/Editor/TMP_SpriteAssetImporter.cs
+++ b/Scripts/Editor/TMP_SpriteAssetImporter.cs
@@ -73,6 +73,8 @@ void DrawEditorPanel()
GUILayout.Space(10);
+ GUI.enabled = m_JsonFile != null && m_SpriteAtlas != null && m_SpriteDataFormat == SpriteAssetImportFormats.TexturePacker;
+
// Create Sprite Asset
if (GUILayout.Button("Create Sprite Asset"))
{
@@ -98,6 +100,8 @@ void DrawEditorPanel()
}
+ GUI.enabled = true;
+
// Creation Feedback
GUILayout.Space(5);
GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(60));
@@ -107,7 +111,8 @@ void DrawEditorPanel()
GUILayout.EndVertical();
GUILayout.Space(5);
- GUI.enabled = m_SpriteInfoList != null ? true : false; // Enable Save Button if font_Atlas is not Null.
+
+ GUI.enabled = m_JsonFile != null && m_SpriteAtlas && m_SpriteInfoList != null && m_SpriteInfoList.Count > 0; // Enable Save Button if font_Atlas is not Null.
if (GUILayout.Button("Save Sprite Asset"))
{
string filePath = string.Empty;
diff --git a/Scripts/Editor/TMPro_ContextMenus.cs b/Scripts/Editor/TMPro_ContextMenus.cs
index c2394d3..90323e0 100644
--- a/Scripts/Editor/TMPro_ContextMenus.cs
+++ b/Scripts/Editor/TMPro_ContextMenus.cs
@@ -240,7 +240,7 @@ static void PasteAtlas(MenuCommand command)
// Context Menus for TMPro Font Assets
//This function is used for debugging and fixing potentially broken font atlas links.
- [MenuItem("CONTEXT/TMP_FontAsset/Extract Atlas", false, 2000)]
+ [MenuItem("CONTEXT/TMP_FontAsset/Extract Atlas", false, 2100)]
static void ExtractAtlas(MenuCommand command)
{
TMP_FontAsset font = command.context as TMP_FontAsset;
@@ -269,12 +269,36 @@ static void ExtractAtlas(MenuCommand command)
DestroyImmediate(tex);
}
+ ///
+ ///
+ ///
+ ///
+ [MenuItem("CONTEXT/TMP_FontAsset/Update Atlas Texture", false, 2000)]
+ static void RegenerateFontAsset(MenuCommand command)
+ {
+ TMP_FontAsset fontAsset = command.context as TMP_FontAsset;
+
+ if (fontAsset != null && Selection.activeObject != fontAsset)
+ {
+ Selection.activeObject = fontAsset;
+ }
- //[MenuItem("CONTEXT/Asset Creator/Extra", false, 1000)]
- //static void Extra(MenuCommand command)
- //{
+ TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(fontAsset);
+ }
- //}
+ [MenuItem("CONTEXT/TrueTypeFontImporter/Create TMP Font Asset", false, 200)]
+ static void CreateFontAsset(MenuCommand command)
+ {
+ TrueTypeFontImporter importer = command.context as TrueTypeFontImporter;
+
+ if (importer != null)
+ {
+ Font sourceFontFile = AssetDatabase.LoadAssetAtPath(importer.assetPath);
+
+ if (sourceFontFile)
+ TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(sourceFontFile);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs b/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs
index ee058da..bbf75b8 100644
--- a/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs
+++ b/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs
@@ -1,70 +1,113 @@
using UnityEngine;
using UnityEditor;
-using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.IO;
-using System.Linq;
-
namespace TMPro.EditorUtilities
{
-
public class TMPro_FontAssetCreatorWindow : EditorWindow
{
- //private GUIContent m_MenuItem1 = new GUIContent("Menu Item 1");
- ////private GUIContent m_MenuItem2 = new GUIContent("Menu Item 2");
+ [MenuItem("Window/TextMeshPro/Font Asset Creator", false, 2025)]
+ public static void ShowFontAtlasCreatorWindow()
+ {
+ var window = GetWindow();
+ window.titleContent = new GUIContent("Font Creator");
+ window.Focus();
- ////Implement IHasCustomMenu.AddItemsToMenu
- //public void AddItemsToMenu(GenericMenu menu)
- //{
- // menu.AddItem(m_MenuItem1, false, MenuItem1Selected);
- // //menu.AddItem(m_MenuItem2, m_Item2On, MenuItem2Selected);
- //}
+ // Make sure TMP Essential Resources have been imported.
+ window.CheckEssentialResources();
+ }
- //private void MenuItem1Selected()
- //{
- // Debug.Log("Menu Item 1 selected");
- //}
- [MenuItem("Window/TextMeshPro/Font Asset Creator", false, 2025)]
- public static void ShowFontAtlasCreatorWindow()
+ public static void ShowFontAtlasCreatorWindow(Font sourceFontFile)
{
var window = GetWindow();
+
+ window.titleContent = new GUIContent("Font Creator");
+ window.Focus();
+
+ window.ClearGeneratedData();
+ window.m_LegacyFontAsset = null;
+ window.m_SelectedFontAsset = null;
+
+ // Override selected font asset
+ window.m_SourceFontFile = sourceFontFile;
+
+ // Make sure TMP Essential Resources have been imported.
+ window.CheckEssentialResources();
+ }
+
+
+ public static void ShowFontAtlasCreatorWindow(TMP_FontAsset fontAsset)
+ {
+ var window = GetWindow();
+
window.titleContent = new GUIContent("Asset Creator");
window.Focus();
+
+ // Clear any previously generated data
+ window.ClearGeneratedData();
+ window.m_LegacyFontAsset = null;
+
+ // Load font asset creation settings if we have valid settings
+ if (string.IsNullOrEmpty(fontAsset.creationSettings.sourceFontFileGUID) == false)
+ {
+ window.LoadFontCreationSettings(fontAsset.creationSettings);
+ window.m_ReferencedFontAsset = fontAsset;
+ window.m_SavedFontAtlas = fontAsset.atlas;
+ }
+ else
+ {
+ window.m_WarningMessage = "Font Asset [" + fontAsset.name + "] does not contain any previous \"Font Asset Creation Settings\". This usually means [" + fontAsset.name + "] was created before this new functionality was added.";
+ window.m_SourceFontFile = null;
+ window.m_LegacyFontAsset = fontAsset;
+ }
+
+ // Even if we don't have any saved generation settings, we still want to pre-select the source font file.
+ window.m_SelectedFontAsset = fontAsset;
+
+ // Make sure TMP Essential Resources have been imported.
+ window.CheckEssentialResources();
}
private string[] FontSizingOptions = { "Auto Sizing", "Custom Size" };
- private int FontSizingOption_Selection = 0;
- private string[] FontResolutionLabels = { "16","32", "64", "128", "256", "512", "1024", "2048", "4096", "8192" };
- private int[] FontAtlasResolutions = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
+ private int m_PointSizeSamplingMode = 0;
+ private string[] FontResolutionLabels = { "8", "16","32", "64", "128", "256", "512", "1024", "2048", "4096", "8192" };
+ private int[] FontAtlasResolutions = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
private string[] FontCharacterSets = { "ASCII", "Extended ASCII", "ASCII Lowercase", "ASCII Uppercase", "Numbers + Symbols", "Custom Range", "Unicode Range (Hex)", "Custom Characters", "Characters from File" };
private enum FontPackingModes { Fast = 0, Optimum = 4 };
- private FontPackingModes m_fontPackingSelection = 0;
+ private FontPackingModes m_PackingMode = 0;
- private int font_CharacterSet_Selection = 0;
+ private int m_CharacterSetSelectionMode = 0;
private enum PreviewSelectionTypes { PreviewFont, PreviewTexture, PreviewDistanceField };
private PreviewSelectionTypes previewSelection;
- private string characterSequence = "";
- private string output_feedback = "";
+ private string m_CharacterSequence = "";
+ private string m_Output_feedback = "";
private string output_name_label = "Font: ";
private string output_size_label = "Pt. Size: ";
private string output_count_label = "Characters packed: ";
+ private string m_WarningMessage;
private int m_character_Count;
private Vector2 output_ScrollPosition;
- //private GUISkin TMP_GUISkin;
- //private GUIStyle TextureAreaBox;
- //private GUIStyle TextAreaBox;
- //private GUIStyle Section_Label;
+ [System.Serializable]
+ class FontAssetCreationSettingsContainer
+ {
+ public List fontAssetCreationSettings;
+ }
+ private FontAssetCreationSettingsContainer m_FontAssetCreationSettingsContainer;
+ //private string[] m_FontCreationPresets = new string[] { "Recent 1", "Recent 2", "Recent 3", "Recent 4" };
+ private int m_FontAssetCreationSettingsCurrentIndex = 0;
+ private const string k_FontAssetCreationSettingsContainerKey = "TextMeshPro.FontAssetCreator.RecentFontAssetCreationSettings.Container";
+ private const string k_FontAssetCreationSettingsCurrentIndexKey = "TextMeshPro.FontAssetCreator.RecentFontAssetCreationSettings.CurrentIndex";
//private Thread MainThread;
- private Color[] Output;
+ private Color[] Output = null;
private bool isDistanceMapReady = false;
private bool isRepaintNeeded = false;
@@ -72,34 +115,33 @@ private enum PreviewSelectionTypes { PreviewFont, PreviewTexture, PreviewDistanc
public static float ProgressPercentage;
private float m_renderingProgress;
private bool isRenderingDone = false;
- private bool isProcessing = false;
+ private bool m_IsProcessing = false;
+ private bool m_IsGenerationDisabled = false;
private bool isGenerationCancelled = false;
-
- private Object font_TTF;
- private TMP_FontAsset m_fontAssetSelection;
- private TextAsset characterList;
- private int font_size;
-
- private int font_padding = 5;
- private FaceStyles font_style = FaceStyles.Normal;
- private float font_style_mod = 2;
- private RenderModes font_renderMode = RenderModes.DistanceField16;
- private int font_atlas_width = 512;
- private int font_atlas_height = 512;
-
- //private int m_shaderSelectionIndex;
- //private Shader m_shaderSelection;
- //private string[] m_availableShaderNames;
- //private Shader[] m_availableShaders;
-
+ private bool m_IsFontAtlasInvalid;
+
+ private Font m_SourceFontFile;
+ private TMP_FontAsset m_SelectedFontAsset;
+ private TMP_FontAsset m_ReferencedFontAsset;
+ private TMP_FontAsset m_LegacyFontAsset;
+ private TextAsset m_CharactersFromFile;
+ private int m_PointSize;
+
+ private int m_Padding = 5;
+ private FaceStyles m_FontStyle = FaceStyles.Normal;
+ private float m_FontStyleValue = 2;
+ private RenderModes m_RenderMode = RenderModes.DistanceField16;
+ private int m_AtlasWidth = 512;
+ private int m_AtlasHeight = 512;
private int font_scaledownFactor = 1;
- //private int font_spread = 4;
+
private FT_FaceInfo m_font_faceInfo;
private FT_GlyphInfo[] m_font_glyphInfo;
private byte[] m_texture_buffer;
- private Texture2D m_font_Atlas;
+ private Texture2D m_Font_Atlas;
+ private Texture2D m_SavedFontAtlas;
//private Texture2D m_texture_Atlas;
//private int m_packingMethod = 0;
@@ -111,7 +153,8 @@ private enum PreviewSelectionTypes { PreviewFont, PreviewTexture, PreviewDistanc
//private Texture2D sdf_Atlas;
//private int downscale;
- //private Object prev_Selection;
+ // Diagnostics
+ private System.Diagnostics.Stopwatch m_stopWatch;
private EditorWindow m_editorWindow;
private Vector2 m_previewWindow_Size = new Vector2(768, 768);
@@ -120,7 +163,9 @@ private enum PreviewSelectionTypes { PreviewFont, PreviewTexture, PreviewDistanc
public void OnEnable()
{
-
+ // Used for Diagnostics
+ m_stopWatch = new System.Diagnostics.Stopwatch();
+
m_editorWindow = this;
UpdateEditorWindowSize(768, 768);
@@ -130,14 +175,24 @@ public void OnEnable()
// Initialize & Get shader property IDs.
ShaderUtilities.GetShaderPropertyIDs();
- // Add Event Listener related to Distance Field Atlas Creation.
- TMPro_EventManager.COMPUTE_DT_EVENT.Add(ON_COMPUTE_DT_EVENT);
+ // Load last selected preset if we are not already in the process of regenerating an existing font asset (via the Context menu)
+ if (EditorPrefs.HasKey(k_FontAssetCreationSettingsContainerKey))
+ {
+ if (m_FontAssetCreationSettingsContainer == null)
+ m_FontAssetCreationSettingsContainer = JsonUtility.FromJson(EditorPrefs.GetString(k_FontAssetCreationSettingsContainerKey));
+
+ if (m_FontAssetCreationSettingsContainer.fontAssetCreationSettings != null && m_FontAssetCreationSettingsContainer.fontAssetCreationSettings.Count > 0)
+ {
+ // Load Font Asset Creation Settings preset.
+ if (EditorPrefs.HasKey(k_FontAssetCreationSettingsCurrentIndexKey))
+ m_FontAssetCreationSettingsCurrentIndex = EditorPrefs.GetInt(k_FontAssetCreationSettingsCurrentIndexKey);
+
+ LoadFontCreationSettings(m_FontAssetCreationSettingsContainer.fontAssetCreationSettings[m_FontAssetCreationSettingsCurrentIndex]);
+ }
+ }
// Debug Link to received message from Native Code
//TMPro_FontPlugin.LinkDebugLog(); // Link with C++ Plugin to get Debug output
-
- // Get Shader List
- //m_availableShaderNames = UpdateShaderList(font_renderMode, out m_availableShaders);
}
@@ -145,8 +200,6 @@ public void OnDisable()
{
//Debug.Log("TextMeshPro Editor Window has been disabled.");
- TMPro_EventManager.COMPUTE_DT_EVENT.Remove(ON_COMPUTE_DT_EVENT);
-
// Cancel font asset generation just in case one is in progress.
TMPro_FontPlugin.SendCancellationRequest(CancellationRequestType.WindowClosed);
@@ -160,57 +213,70 @@ public void OnDisable()
DestroyImmediate(m_destination_Atlas);
}
- if (m_font_Atlas != null && EditorUtility.IsPersistent(m_font_Atlas) == false)
+ if (m_Font_Atlas != null && EditorUtility.IsPersistent(m_Font_Atlas) == false)
{
//Debug.Log("Destroying font_Atlas!");
- DestroyImmediate(m_font_Atlas);
+ DestroyImmediate(m_Font_Atlas);
}
- string projectPath = Path.GetFullPath("Assets/..");
- if (System.IO.File.Exists(projectPath + "/Assets/Glyph Report.txt"))
+ // Remove Glyph Report if one was created.
+ if (File.Exists("Assets/TextMesh Pro/Glyph Report.txt"))
{
- System.IO.File.Delete(projectPath + "/Assets/Glyph Report.txt");
- System.IO.File.Delete(projectPath + "/Assets/Glyph Report.txt.meta");
+ File.Delete("Assets/TextMesh Pro/Glyph Report.txt");
+ File.Delete("Assets/TextMesh Pro/Glyph Report.txt.meta");
AssetDatabase.Refresh();
}
+ // Save Font Asset Creation Settings Index
+ SaveCreationSettingsToEditorPrefs(SaveFontCreationSettings());
+ EditorPrefs.SetInt(k_FontAssetCreationSettingsCurrentIndexKey, m_FontAssetCreationSettingsCurrentIndex);
+
+ // Unregister to event
+ TMPro_EventManager.RESOURCE_LOAD_EVENT.Remove(ON_RESOURCES_LOADED);
+
Resources.UnloadUnusedAssets();
}
- public void OnGUI()
+ // Event received when TMP resources have been loaded.
+ void ON_RESOURCES_LOADED()
{
- GUILayout.BeginHorizontal(GUILayout.Width(310));
- DrawControls();
+ TMPro_EventManager.RESOURCE_LOAD_EVENT.Remove(ON_RESOURCES_LOADED);
- DrawPreview();
- GUILayout.EndHorizontal();
+ m_IsGenerationDisabled = false;
}
- public void ON_COMPUTE_DT_EVENT(object Sender, Compute_DT_EventArgs e)
+ // Make sure TMP Essential Resources have been imported.
+ void CheckEssentialResources()
{
- if (e.EventType == Compute_DistanceTransform_EventTypes.Completed)
- {
- Output = e.Colors;
- isProcessing = false;
- isDistanceMapReady = true;
- }
- else if (e.EventType == Compute_DistanceTransform_EventTypes.Processing)
+ if (TMP_Settings.instance == null)
{
- ProgressPercentage = e.ProgressPercentage;
- isRepaintNeeded = true;
+ if (m_IsGenerationDisabled == false)
+ TMPro_EventManager.RESOURCE_LOAD_EVENT.Add(ON_RESOURCES_LOADED);
+
+ m_IsGenerationDisabled = true;
}
}
+ public void OnGUI()
+ {
+ GUILayout.BeginHorizontal(GUILayout.Width(310));
+ DrawControls();
+
+ DrawPreview();
+ GUILayout.EndHorizontal();
+ }
+
+
public void Update()
{
if (isDistanceMapReady)
{
- if (m_font_Atlas != null)
+ if (m_Font_Atlas != null)
{
- m_destination_Atlas = new Texture2D(m_font_Atlas.width / font_scaledownFactor, m_font_Atlas.height / font_scaledownFactor, TextureFormat.Alpha8, false, true);
+ m_destination_Atlas = new Texture2D(m_Font_Atlas.width / font_scaledownFactor, m_Font_Atlas.height / font_scaledownFactor, TextureFormat.Alpha8, false, true);
m_destination_Atlas.SetPixels(Output);
m_destination_Atlas.Apply(false, true);
}
@@ -237,7 +303,7 @@ public void Update()
}
// Update Progress bar is we are Rendering a Font.
- if (isProcessing)
+ if (m_IsProcessing)
{
m_renderingProgress = TMPro_FontPlugin.Check_RenderProgress();
@@ -247,7 +313,12 @@ public void Update()
// Update Feedback Window & Create Font Texture once Rendering is done.
if (isRenderingDone)
{
- isProcessing = false;
+ // Stop StopWatch
+ m_stopWatch.Stop();
+ Debug.Log("Font Atlas generation completed in: " + m_stopWatch.Elapsed.TotalMilliseconds.ToString("0.000 ms."));
+ m_stopWatch.Reset();
+
+ m_IsProcessing = false;
isRenderingDone = false;
if (isGenerationCancelled == false)
@@ -336,7 +407,21 @@ void DrawControls()
{
GUILayout.BeginVertical();
GUILayout.Label("TextMeshPro - Font Asset Creator", TMP_UIStyleManager.Section_Label, GUILayout.Width(300));
- GUILayout.Label("Font Settings", TMP_UIStyleManager.Section_Label, GUILayout.Width(300));
+
+ Rect rect = EditorGUILayout.GetControlRect(false, 25);
+ GUI.Label(rect, m_SelectedFontAsset != null ? string.Format("Creation Settings ({0})", m_SelectedFontAsset.name) : "Creation Settings", TMP_UIStyleManager.Section_Label);
+
+ // Display Recent Font Asset Creation Settings
+ //EditorGUI.BeginChangeCheck();
+ //rect.x += 170; rect.y += 4; rect.width = rect.width - 175;
+ //m_FontAssetCreationSettingsCurrentIndex = EditorGUI.Popup(rect, m_FontAssetCreationSettingsCurrentIndex, m_FontCreationPresets);
+ //if (EditorGUI.EndChangeCheck())
+ //{
+ // // Load creation settings
+ // LoadFontCreationSettings(m_FontAssetCreationSettingsContainer.fontAssetCreationSettings[m_FontAssetCreationSettingsCurrentIndex]);
+ // m_IsFontAtlasInvalid = true;
+ // m_SelectedFontAsset = null;
+ //}
GUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox, GUILayout.Width(300));
@@ -344,218 +429,277 @@ void DrawControls()
EditorGUIUtility.fieldWidth = 160f;
// Disable Options if already generating a font atlas texture.
- GUI.enabled = isProcessing ? false : true;
-
- // FONT TTF SELECTION
- EditorGUI.BeginChangeCheck();
- font_TTF = EditorGUILayout.ObjectField("Font Source", font_TTF, typeof(Font), false, GUILayout.Width(290)) as Font;
- if (EditorGUI.EndChangeCheck())
+ EditorGUI.BeginDisabledGroup(m_IsProcessing);
{
- //
- }
+ // FONT TTF SELECTION
+ EditorGUI.BeginChangeCheck();
+ m_SourceFontFile = EditorGUILayout.ObjectField("Font Source", m_SourceFontFile, typeof(Font), false) as Font;
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_SelectedFontAsset = null;
+ m_IsFontAtlasInvalid = true;
+ }
- // FONT SIZING
- if (FontSizingOption_Selection == 0)
- {
- FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(290));
- }
- else
- {
+ // FONT SIZING
+ EditorGUI.BeginChangeCheck();
+ if (m_PointSizeSamplingMode == 0)
+ {
+ m_PointSizeSamplingMode = EditorGUILayout.Popup("Font Size", m_PointSizeSamplingMode, FontSizingOptions);
+ }
+ else
+ {
+ EditorGUIUtility.labelWidth = 120f;
+ EditorGUIUtility.fieldWidth = 80f;
+
+ GUILayout.BeginHorizontal();
+ m_PointSizeSamplingMode = EditorGUILayout.Popup("Font Size", m_PointSizeSamplingMode, FontSizingOptions);
+ m_PointSize = EditorGUILayout.IntField(m_PointSize);
+ GUILayout.EndHorizontal();
+ }
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
EditorGUIUtility.labelWidth = 120f;
- EditorGUIUtility.fieldWidth = 40f;
+ EditorGUIUtility.fieldWidth = 160f;
- GUILayout.BeginHorizontal(GUILayout.Width(290));
- FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(225));
- font_size = EditorGUILayout.IntField(font_size);
- GUILayout.EndHorizontal();
- }
+ // FONT PADDING
+ EditorGUI.BeginChangeCheck();
+ m_Padding = EditorGUILayout.IntField("Font Padding", m_Padding);
+ m_Padding = (int)Mathf.Clamp(m_Padding, 0f, 64f);
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- EditorGUIUtility.labelWidth = 120f;
- EditorGUIUtility.fieldWidth = 160f;
+ // FONT PACKING METHOD SELECTION
+ EditorGUI.BeginChangeCheck();
+ m_PackingMode = (FontPackingModes)EditorGUILayout.EnumPopup("Packing Method", m_PackingMode);
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- // FONT PADDING
- font_padding = EditorGUILayout.IntField("Font Padding", font_padding, GUILayout.Width(290));
- font_padding = (int)Mathf.Clamp(font_padding, 0f, 64f);
+ // FONT ATLAS RESOLUTION SELECTION
+ GUILayout.BeginHorizontal();
+ GUI.changed = false;
- // FONT PACKING METHOD SELECTION
- m_fontPackingSelection = (FontPackingModes)EditorGUILayout.EnumPopup("Packing Method", m_fontPackingSelection, GUILayout.Width(225));
-
- //font_renderingMode = (FontRenderingMode)EditorGUILayout.EnumPopup("Rendering Mode", font_renderingMode, GUILayout.Width(290));
+ EditorGUIUtility.labelWidth = 120f;
+ EditorGUIUtility.fieldWidth = 40f;
- // FONT ATLAS RESOLUTION SELECTION
- GUILayout.BeginHorizontal(GUILayout.Width(290));
- GUI.changed = false;
+ EditorGUI.BeginChangeCheck();
+ GUILayout.Label("Atlas Resolution:", GUILayout.Width(116));
+ m_AtlasWidth = EditorGUILayout.IntPopup(m_AtlasWidth, FontResolutionLabels, FontAtlasResolutions);
+ m_AtlasHeight = EditorGUILayout.IntPopup(m_AtlasHeight, FontResolutionLabels, FontAtlasResolutions);
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- EditorGUIUtility.labelWidth = 120f;
- EditorGUIUtility.fieldWidth = 40f;
+ GUILayout.EndHorizontal();
- GUILayout.Label("Atlas Resolution:", GUILayout.Width(116));
- font_atlas_width = EditorGUILayout.IntPopup(font_atlas_width, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80));
- font_atlas_height = EditorGUILayout.IntPopup(font_atlas_height, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80));
+ // FONT CHARACTER SET SELECTION
+ EditorGUI.BeginChangeCheck();
+ bool hasSelectionChanged = false;
+ m_CharacterSetSelectionMode = EditorGUILayout.Popup("Character Set", m_CharacterSetSelectionMode, FontCharacterSets);
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_CharacterSequence = "";
+ hasSelectionChanged = true;
+ m_IsFontAtlasInvalid = true;
+ }
- GUILayout.EndHorizontal();
+ switch (m_CharacterSetSelectionMode)
+ {
+ case 0: // ASCII
+ //characterSequence = "32 - 126, 130, 132 - 135, 139, 145 - 151, 153, 155, 161, 166 - 167, 169 - 174, 176, 181 - 183, 186 - 187, 191, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252 - 8254, 8260, 8286";
+ m_CharacterSequence = "32 - 126, 160, 8203, 8230, 9633";
+ break;
+
+ case 1: // EXTENDED ASCII
+ m_CharacterSequence = "32 - 126, 160 - 255, 8192 - 8303, 8364, 8482, 9633";
+ // Could add 9632 for missing glyph
+ break;
+
+ case 2: // Lowercase
+ m_CharacterSequence = "32 - 64, 91 - 126, 160";
+ break;
+
+ case 3: // Uppercase
+ m_CharacterSequence = "32 - 96, 123 - 126, 160";
+ break;
+
+ case 4: // Numbers & Symbols
+ m_CharacterSequence = "32 - 64, 91 - 96, 123 - 126, 160";
+ break;
+
+ case 5: // Custom Range
+ EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
+ GUILayout.Label("Enter a sequence of decimal values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label);
+ GUILayout.Space(10f);
+
+ EditorGUI.BeginChangeCheck();
+ m_ReferencedFontAsset = EditorGUILayout.ObjectField("Select Font Asset", m_ReferencedFontAsset, typeof(TMP_FontAsset), false) as TMP_FontAsset;
+ if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
+ {
+ if (m_ReferencedFontAsset != null)
+ m_CharacterSequence = TMP_EditorUtility.GetDecimalCharacterSequence(TMP_FontAsset.GetCharactersArray(m_ReferencedFontAsset));
+
+ m_IsFontAtlasInvalid = true;
+ }
+ EditorGUIUtility.labelWidth = 120;
- // FONT CHARACTER SET SELECTION
- EditorGUI.BeginChangeCheck();
- bool hasSelectionChanged = false;
- font_CharacterSet_Selection = EditorGUILayout.Popup("Character Set", font_CharacterSet_Selection, FontCharacterSets, GUILayout.Width(290));
- if (EditorGUI.EndChangeCheck())
- {
- characterSequence = "";
- hasSelectionChanged = true;
- //Debug.Log("Resetting Sequence!");
- }
+ // Filter out unwanted characters.
+ char chr = Event.current.character;
+ if ((chr < '0' || chr > '9') && (chr < ',' || chr > '-'))
+ {
+ Event.current.character = '\0';
+ }
- switch (font_CharacterSet_Selection)
- {
- case 0: // ASCII
- //characterSequence = "32 - 126, 130, 132 - 135, 139, 145 - 151, 153, 155, 161, 166 - 167, 169 - 174, 176, 181 - 183, 186 - 187, 191, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252 - 8254, 8260, 8286";
- characterSequence = "32 - 126, 160, 8203, 8230, 9633";
- break;
-
- case 1: // EXTENDED ASCII
- characterSequence = "32 - 126, 160 - 255, 8192 - 8303, 8364, 8482, 9633";
- // Could add 9632 for missing glyph
- break;
-
- case 2: // Lowercase
- characterSequence = "32 - 64, 91 - 126, 160";
- break;
-
- case 3: // Uppercase
- characterSequence = "32 - 96, 123 - 126, 160";
- break;
-
- case 4: // Numbers & Symbols
- characterSequence = "32 - 64, 91 - 96, 123 - 126, 160";
- break;
-
- case 5: // Custom Range
- EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
- GUILayout.Label("Enter a sequence of decimal values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label);
- GUILayout.Space(10f);
-
- EditorGUI.BeginChangeCheck();
- m_fontAssetSelection = EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290)) as TMP_FontAsset;
- if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
- {
- if (m_fontAssetSelection != null)
- characterSequence = TMP_EditorUtility.GetDecimalCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection));
- }
+ GUILayout.Label("Character Sequence (Decimal)", TMP_UIStyleManager.Section_Label);
+ EditorGUI.BeginChangeCheck();
+ m_CharacterSequence = EditorGUILayout.TextArea(m_CharacterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(285));
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
+
+ EditorGUILayout.EndVertical();
+ break;
- EditorGUIUtility.labelWidth = 120;
+ case 6: // Unicode HEX Range
+ EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
+ GUILayout.Label("Enter a sequence of Unicode (hex) values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label);
+ GUILayout.Space(10f);
+ EditorGUI.BeginChangeCheck();
+ m_ReferencedFontAsset = EditorGUILayout.ObjectField("Select Font Asset", m_ReferencedFontAsset, typeof(TMP_FontAsset), false) as TMP_FontAsset;
+ if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
+ {
+ if (m_ReferencedFontAsset != null)
+ m_CharacterSequence = TMP_EditorUtility.GetUnicodeCharacterSequence(TMP_FontAsset.GetCharactersArray(m_ReferencedFontAsset));
- // Filter out unwanted characters.
- char chr = Event.current.character;
- if ((chr < '0' || chr > '9') && (chr < ',' || chr > '-'))
- {
- Event.current.character = '\0';
- }
- GUILayout.Label("Character Sequence (Decimal)", TMP_UIStyleManager.Section_Label);
- characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(290));
+ m_IsFontAtlasInvalid = true;
+ }
- EditorGUILayout.EndVertical();
- break;
+ EditorGUIUtility.labelWidth = 120;
- case 6: // Unicode HEX Range
- EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
- GUILayout.Label("Enter a sequence of Unicode (hex) values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label);
- GUILayout.Space(10f);
- EditorGUI.BeginChangeCheck();
- m_fontAssetSelection = EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290)) as TMP_FontAsset;
- if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
- {
- if (m_fontAssetSelection != null)
- characterSequence = TMP_EditorUtility.GetUnicodeCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection));
- }
+ // Filter out unwanted characters.
+ chr = Event.current.character;
+ if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F') && (chr < ',' || chr > '-'))
+ {
+ Event.current.character = '\0';
+ }
+ GUILayout.Label("Character Sequence (Hex)", TMP_UIStyleManager.Section_Label);
+ EditorGUI.BeginChangeCheck();
+ m_CharacterSequence = EditorGUILayout.TextArea(m_CharacterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(285));
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- EditorGUIUtility.labelWidth = 120;
+ EditorGUILayout.EndVertical();
+ break;
+ case 7: // Characters from Font Asset
+ EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
+ GUILayout.Label("Type the characters to be included in the font asset or retrieve them from another font asset.", TMP_UIStyleManager.Label);
+ GUILayout.Space(10f);
- // Filter out unwanted characters.
- chr = Event.current.character;
- if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F') && (chr < ',' || chr > '-'))
- {
- Event.current.character = '\0';
- }
- GUILayout.Label("Character Sequence (Hex)", TMP_UIStyleManager.Section_Label);
- characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(290));
+ EditorGUI.BeginChangeCheck();
+ m_ReferencedFontAsset = EditorGUILayout.ObjectField("Select Font Asset", m_ReferencedFontAsset, typeof(TMP_FontAsset), false) as TMP_FontAsset;
+ if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
+ {
+ if (m_ReferencedFontAsset != null)
+ m_CharacterSequence = TMP_FontAsset.GetCharacters(m_ReferencedFontAsset);
- EditorGUILayout.EndVertical();
- break;
+ m_IsFontAtlasInvalid = true;
+ }
- case 7: // Characters from Font Asset
- EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox);
- GUILayout.Label("Type the characters to be included in the font asset or retrieve them from another font asset.", TMP_UIStyleManager.Label);
- GUILayout.Space(10f);
+ EditorGUIUtility.labelWidth = 120;
- EditorGUI.BeginChangeCheck();
- m_fontAssetSelection = EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290)) as TMP_FontAsset;
- if (EditorGUI.EndChangeCheck() || hasSelectionChanged)
- {
- if (m_fontAssetSelection != null)
- characterSequence = TMP_FontAsset.GetCharacters(m_fontAssetSelection);
- }
+ EditorGUI.indentLevel = 0;
- EditorGUIUtility.labelWidth = 120;
+ GUILayout.Label("Custom Character List", TMP_UIStyleManager.Section_Label);
+ EditorGUI.BeginChangeCheck();
+ m_CharacterSequence = EditorGUILayout.TextArea(m_CharacterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(285));
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- EditorGUI.indentLevel = 0;
+ EditorGUILayout.EndVertical();
+ break;
- GUILayout.Label("Custom Character List", TMP_UIStyleManager.Section_Label);
- characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120), GUILayout.MaxWidth(290));
- EditorGUILayout.EndVertical();
- break;
+ case 8: // Character List from File
+ EditorGUI.BeginChangeCheck();
+ m_CharactersFromFile = EditorGUILayout.ObjectField("Character File", m_CharactersFromFile, typeof(TextAsset), false) as TextAsset;
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- case 8: // Character List from File
- characterList = EditorGUILayout.ObjectField("Character File", characterList, typeof(TextAsset), false, GUILayout.Width(290)) as TextAsset;
- if (characterList != null)
- {
- characterSequence = characterList.text;
- }
- break;
- }
+ if (m_CharactersFromFile != null)
+ {
+ m_CharacterSequence = m_CharactersFromFile.text;
+ }
+ break;
+ }
- EditorGUIUtility.labelWidth = 120f;
- EditorGUIUtility.fieldWidth = 40f;
+ EditorGUIUtility.labelWidth = 120f;
+ EditorGUIUtility.fieldWidth = 80f;
- // FONT STYLE SELECTION
- GUILayout.BeginHorizontal(GUILayout.Width(290));
- font_style = (FaceStyles)EditorGUILayout.EnumPopup("Font Style:", font_style, GUILayout.Width(225));
- font_style_mod = EditorGUILayout.IntField((int)font_style_mod);
- GUILayout.EndHorizontal();
+ // FONT STYLE SELECTION
+ EditorGUI.BeginChangeCheck();
+ GUILayout.BeginHorizontal();
+ m_FontStyle = (FaceStyles)EditorGUILayout.EnumPopup("Font Style:", m_FontStyle);
+ m_FontStyleValue = EditorGUILayout.IntField((int)m_FontStyleValue);
+ GUILayout.EndHorizontal();
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_IsFontAtlasInvalid = true;
+ }
- // Render Mode Selection
- EditorGUI.BeginChangeCheck();
- font_renderMode = (RenderModes)EditorGUILayout.EnumPopup("Font Render Mode:", font_renderMode, GUILayout.Width(290));
- if (EditorGUI.EndChangeCheck())
- {
- //m_availableShaderNames = UpdateShaderList(font_renderMode, out m_availableShaders);
+ // Render Mode Selection
+ EditorGUI.BeginChangeCheck();
+ m_RenderMode = (RenderModes)EditorGUILayout.EnumPopup("Font Render Mode:", m_RenderMode);
+ if (EditorGUI.EndChangeCheck())
+ {
+ //m_availableShaderNames = UpdateShaderList(font_renderMode, out m_availableShaders);
+ m_IsFontAtlasInvalid = true;
+ }
+
+ includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs);
}
+ EditorGUI.EndDisabledGroup();
- // Default Shader
- //EditorGUI.BeginChangeCheck();
- //m_shaderSelectionIndex = EditorGUILayout.Popup("Default Shader", m_shaderSelectionIndex, m_availableShaderNames);
- //if (EditorGUI.EndChangeCheck())
- // m_shaderSelection = m_availableShaders[m_shaderSelectionIndex];
+ GUILayout.Space(5);
- includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs, GUILayout.MaxWidth(290));
+ if (!string.IsNullOrEmpty(m_WarningMessage))
+ {
+ EditorGUILayout.HelpBox(m_WarningMessage, MessageType.Warning);
+ }
EditorGUIUtility.labelWidth = 120f;
EditorGUIUtility.fieldWidth = 160f;
- GUILayout.Space(20);
+ GUILayout.Space(15);
- bool isEnabled = GUI.enabled = font_TTF == null || isProcessing ? false : true; // Enable Preview if we are not already rendering a font.
- if (GUILayout.Button("Generate Font Atlas", GUILayout.Width(290)) && characterSequence.Length != 0 && GUI.enabled)
+ // GENERATE FONT ASSET
+ // Generation options are disabled if we do not have a source font file selected or are already generating.
+ bool isEnabled = GUI.enabled = m_SourceFontFile == null || m_IsProcessing || m_IsGenerationDisabled ? false : true;
+ if (GUILayout.Button("Generate Font Atlas") && m_CharacterSequence.Length != 0 && GUI.enabled)
{
- if (isProcessing == false && font_TTF != null)
+ if (m_IsProcessing == false && m_SourceFontFile != null)
{
int error_Code;
- m_font_Atlas = null;
+
+ DestroyImmediate(m_Font_Atlas);
+ m_Font_Atlas = null;
+ m_SavedFontAtlas = null;
error_Code = TMPro_FontPlugin.Initialize_FontEngine(); // Initialize Font Engine
if (error_Code != 0)
@@ -569,7 +713,7 @@ void DrawControls()
Debug.Log("Error Code: " + error_Code + " occurred while Initializing the FreeType Library.");
}
- string fontPath = AssetDatabase.GetAssetPath(font_TTF); // Get file path of TTF Font.
+ string fontPath = AssetDatabase.GetAssetPath(m_SourceFontFile); // Get file path of TTF Font.
if (error_Code == 0)
{
@@ -583,15 +727,15 @@ void DrawControls()
error_Code = 0;
}
else
- Debug.Log("Error Code: " + error_Code + " occurred while Loading the font.");
+ Debug.Log("Error Code: " + error_Code + " occurred while Loading the [" + m_SourceFontFile.name + "] font file. This typically results from the use of an incompatible or corrupted font file.");
}
}
if (error_Code == 0)
{
- if (FontSizingOption_Selection == 0) font_size = 72; // If Auto set size to 72 pts.
+ if (m_PointSizeSamplingMode == 0) m_PointSize = 72; // If Auto set size to 72 pts.
- error_Code = TMPro_FontPlugin.FT_Size_Font(font_size); // Load the selected font and size it accordingly.
+ error_Code = TMPro_FontPlugin.FT_Size_Font(m_PointSize); // Load the selected font and size it accordingly.
if (error_Code != 0)
Debug.Log("Error Code: " + error_Code + " occurred while Sizing the font.");
}
@@ -600,15 +744,15 @@ void DrawControls()
if (error_Code == 0)
{
int[] character_Set = null;
- if (font_CharacterSet_Selection == 7 || font_CharacterSet_Selection == 8)
+ if (m_CharacterSetSelectionMode == 7 || m_CharacterSetSelectionMode == 8)
{
List char_List = new List();
- for (int i = 0; i < characterSequence.Length; i++)
+ for (int i = 0; i < m_CharacterSequence.Length; i++)
{
// Check to make sure we don't include duplicates
- if (char_List.FindIndex(item => item == characterSequence[i]) == -1)
- char_List.Add(characterSequence[i]);
+ if (char_List.FindIndex(item => item == m_CharacterSequence[i]) == -1)
+ char_List.Add(m_CharacterSequence[i]);
else
{
//Debug.Log("Character [" + characterSequence[i] + "] is a duplicate.");
@@ -617,52 +761,55 @@ void DrawControls()
character_Set = char_List.ToArray();
}
- else if (font_CharacterSet_Selection == 6)
+ else if (m_CharacterSetSelectionMode == 6)
{
- character_Set = ParseHexNumberSequence(characterSequence);
+ character_Set = ParseHexNumberSequence(m_CharacterSequence);
}
else
{
- character_Set = ParseNumberSequence(characterSequence);
+ character_Set = ParseNumberSequence(m_CharacterSequence);
}
m_character_Count = character_Set.Length;
- m_texture_buffer = new byte[font_atlas_width * font_atlas_height];
+ m_texture_buffer = new byte[m_AtlasWidth * m_AtlasHeight];
m_font_faceInfo = new FT_FaceInfo();
m_font_glyphInfo = new FT_GlyphInfo[m_character_Count];
- int padding = font_padding;
+ int padding = m_Padding;
- bool autoSizing = FontSizingOption_Selection == 0 ? true : false;
+ bool autoSizing = m_PointSizeSamplingMode == 0 ? true : false;
- float strokeSize = font_style_mod;
- if (font_renderMode == RenderModes.DistanceField16) strokeSize = font_style_mod * 16;
- if (font_renderMode == RenderModes.DistanceField32) strokeSize = font_style_mod * 32;
+ float strokeSize = m_FontStyleValue;
+ if (m_RenderMode == RenderModes.DistanceField16) strokeSize = m_FontStyleValue * 16;
+ if (m_RenderMode == RenderModes.DistanceField32) strokeSize = m_FontStyleValue * 32;
- isProcessing = true;
+ m_IsProcessing = true;
isGenerationCancelled = false;
-
+
+ // Start Stop Watch
+ m_stopWatch = System.Diagnostics.Stopwatch.StartNew();
+
ThreadPool.QueueUserWorkItem(SomeTask =>
{
isRenderingDone = false;
-
- error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, font_atlas_width, font_atlas_height, padding, character_Set, m_character_Count, font_style, strokeSize, autoSizing, font_renderMode,(int)m_fontPackingSelection, ref m_font_faceInfo, m_font_glyphInfo);
+
+ error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, m_AtlasWidth, m_AtlasHeight, padding, character_Set, m_character_Count, m_FontStyle, strokeSize, autoSizing, m_RenderMode,(int)m_PackingMode, ref m_font_faceInfo, m_font_glyphInfo);
isRenderingDone = true;
- //Debug.Log("Font Rendering is completed.");
});
previewSelection = PreviewSelectionTypes.PreviewFont;
}
+
+ SaveCreationSettingsToEditorPrefs(SaveFontCreationSettings());
}
}
-
// FONT RENDERING PROGRESS BAR
GUILayout.Space(1);
- progressRect = GUILayoutUtility.GetRect(0, 20, GUILayout.Width(288));
+ progressRect = EditorGUILayout.GetControlRect(false, 18);
GUI.enabled = true;
EditorGUI.ProgressBar(progressRect, Mathf.Max(0.01f, m_renderingProgress), "Generation Progress");
@@ -670,12 +817,12 @@ void DrawControls()
progressRect.y += 1;
progressRect.width = 20;
progressRect.height = 16;
- GUI.enabled = isProcessing ? true : false;
+ GUI.enabled = m_IsProcessing ? true : false;
if (GUI.Button(progressRect, "X"))
{
TMPro_FontPlugin.SendCancellationRequest(CancellationRequestType.CancelInProgess);
m_renderingProgress = 0;
- isProcessing = false;
+ m_IsProcessing = false;
isGenerationCancelled = true;
}
GUI.enabled = isEnabled;
@@ -685,9 +832,9 @@ void DrawControls()
GUI.skin = TMP_UIStyleManager.TMP_GUISkin;
GUILayout.Space(5);
- GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Width(290));
+ GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow);
output_ScrollPosition = EditorGUILayout.BeginScrollView(output_ScrollPosition, GUILayout.Height(145));
- EditorGUILayout.LabelField(output_feedback, TMP_UIStyleManager.Label);
+ EditorGUILayout.LabelField(m_Output_feedback, TMP_UIStyleManager.Label);
EditorGUILayout.EndScrollView();
GUILayout.EndVertical();
@@ -695,33 +842,44 @@ void DrawControls()
GUILayout.Space(10);
-
// SAVE TEXTURE & CREATE and SAVE FONT XML FILE
- GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null.
- if (GUILayout.Button("Save TextMeshPro Font Asset", GUILayout.Width(290)) && GUI.enabled)
+ GUILayout.BeginHorizontal();
{
- string filePath = string.Empty;
-
- if (font_renderMode < RenderModes.DistanceField16) // == RenderModes.HintedSmooth || font_renderMode == RenderModes.RasterHinted)
+ GUI.enabled = m_Font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null.
+ if (GUILayout.Button("Save") && GUI.enabled)
{
- filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name, "asset");
-
- if (filePath.Length == 0)
- return;
+ if (m_SelectedFontAsset == null)
+ {
+ if (m_LegacyFontAsset != null)
+ SaveNewFontAssetWithSameName(m_LegacyFontAsset);
+ else
+ SaveNewFontAsset(m_SourceFontFile);
+ }
+ else
+ {
+ // Save over exiting Font Asset
+ string filePath = Path.GetFullPath(AssetDatabase.GetAssetPath(m_SelectedFontAsset)).Replace('\\', '/');
- Save_Normal_FontAsset(filePath);
+ if (m_RenderMode < RenderModes.DistanceField16) // ((int)m_RenderMode & 0x10) == 0x10)
+ Save_Normal_FontAsset(filePath);
+ else if (m_RenderMode >= RenderModes.DistanceField16) // ((RasterModes)m_RenderMode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || m_RenderMode == RenderModes.DistanceFieldAA)
+ Save_SDF_FontAsset(filePath);
+ }
}
- else if (font_renderMode >= RenderModes.DistanceField16)
- {
- filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset");
- if (filePath.Length == 0)
- return;
-
- Save_SDF_FontAsset(filePath);
+ if (GUILayout.Button("Save As...") && GUI.enabled)
+ {
+ if (m_SelectedFontAsset == null)
+ {
+ SaveNewFontAsset(m_SourceFontFile);
+ }
+ else
+ {
+ SaveNewFontAssetWithSameName(m_SelectedFontAsset);
+ }
}
-
}
+ GUILayout.EndHorizontal();
GUI.enabled = true; // Re-enable GUI
@@ -731,82 +889,45 @@ void DrawControls()
GUILayout.Space(25);
- /*
- // GENERATE DISTANCE FIELD TEXTURE
- GUILayout.Label("Distance Field Options", SectionLabel, GUILayout.Width(300));
+ // If any options have been changed clear the font atlas as it is now invalid.
+ if (m_IsFontAtlasInvalid)
+ ClearGeneratedData();
+
+ // Figure out the size of the current UI Panel
+ rect = EditorGUILayout.GetControlRect(false, 5);
+ if (Event.current.type == EventType.Repaint)
+ m_UI_Panel_Size = rect;
- GUILayout.BeginVertical(textureAreaBox, GUILayout.Width(300));
+ GUILayout.EndVertical();
+ }
- GUILayout.Space(5);
+ ///
+ /// Clear the previously generated data.
+ ///
+ void ClearGeneratedData()
+ {
+ m_IsFontAtlasInvalid = false;
- font_spread = EditorGUILayout.IntField("Spread", font_spread, GUILayout.Width(280));
- font_scaledownFactor = EditorGUILayout.IntField("Scale down factor", font_scaledownFactor, GUILayout.Width(280));
- if (GUI.changed)
+ if (m_Font_Atlas != null)
{
- EditorPrefs.SetInt("Font_Spread", font_spread);
- EditorPrefs.SetInt("Font_ScaleDownFactor", font_scaledownFactor);
+ DestroyImmediate(m_Font_Atlas);
+ m_Font_Atlas = null;
}
- GUILayout.Space(20);
-
- GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null.
- if (GUILayout.Button("Preview Distance Field Font Atlas", GUILayout.Width(290)))
- {
-
- if (m_font_Atlas != null && isProcessing == false)
- {
- // Generate Distance Field
- int width = m_font_Atlas.width;
- int height = m_font_Atlas.height;
- Color[] colors = m_font_Atlas.GetPixels(); // Should modify this to use Color32 instead
-
- isProcessing = true;
-
- ThreadPool.QueueUserWorkItem(SomeTask => { TMPro_DistanceTransform.Generate(colors, width, height, font_spread, font_scaledownFactor); });
+ m_SavedFontAtlas = null;
- previewSelection = PreviewSelectionTypes.PreviewDistanceField;
- }
- }
-
- GUILayout.Space(1);
-
- progressRect = GUILayoutUtility.GetRect(290, 20, textAreaBox, GUILayout.Width(290), GUILayout.Height(20));
-
- GUI.BeginGroup(progressRect);
-
- GUI.DrawTextureWithTexCoords(new Rect(0, 0, 290, 20), progressTexture, new Rect(1 - ProgressPercentage, 0, 1, 1));
- GUI.EndGroup();
-
- //GUILayout.Space(5);
-
- GUI.enabled = m_destination_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null.
- if (GUILayout.Button("Save TextMeshPro (SDF) Font Asset", GUILayout.Width(290)))
- {
- string filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset");
-
- if (filePath.Length == 0)
- return;
-
- Save_SDF_FontAsset(filePath);
-
- }
-
- GUILayout.EndVertical();
- */
-
- // Figure out the size of the current UI Panel
- Rect rect = EditorGUILayout.GetControlRect(false, 5);
- if (Event.current.type == EventType.Repaint)
- m_UI_Panel_Size = rect;
-
- GUILayout.EndVertical();
+ m_Output_feedback = string.Empty;
+ m_WarningMessage = string.Empty;
}
+ ///
+ /// Function to update the feedback window showing the results of the latest generation.
+ ///
void UpdateRenderFeedbackWindow()
{
- font_size = m_font_faceInfo.pointSize;
+ m_PointSize = m_font_faceInfo.pointSize;
string missingGlyphReport = string.Empty;
@@ -826,7 +947,7 @@ void UpdateRenderFeedbackWindow()
missingGlyphReport += "\n\nMissing Characters";
missingGlyphReport += "\n----------------------------------------";
- output_feedback = missingGlyphReport;
+ m_Output_feedback = missingGlyphReport;
for (int i = 0; i < m_character_Count; i++)
{
@@ -835,18 +956,20 @@ void UpdateRenderFeedbackWindow()
missingGlyphReport += "\nID: " + m_font_glyphInfo[i].id + "\tHex: " + m_font_glyphInfo[i].id.ToString("X") + "\tChar [" + (char)m_font_glyphInfo[i].id + "]";
if (missingGlyphReport.Length < 16300)
- output_feedback = missingGlyphReport;
+ m_Output_feedback = missingGlyphReport;
}
}
if (missingGlyphReport.Length > 16300)
- output_feedback += "\n\nReport truncated.\nSee \"TextMesh Pro\\Glyph Report.txt\"";
+ m_Output_feedback += "\n\nReport truncated.\nSee \"TextMesh Pro\\Glyph Report.txt\"";
// Save Missing Glyph Report file
- string projectPath = Path.GetFullPath("Assets/..");
- missingGlyphReport = System.Text.RegularExpressions.Regex.Replace(missingGlyphReport, @"<[^>]*>", string.Empty);
- System.IO.File.WriteAllText(projectPath + "/Assets/Glyph Report.txt", missingGlyphReport);
- AssetDatabase.Refresh();
+ if (Directory.Exists("Assets/TextMesh Pro"))
+ {
+ missingGlyphReport = System.Text.RegularExpressions.Regex.Replace(missingGlyphReport, @"<[^>]*>", string.Empty);
+ File.WriteAllText("Assets/TextMesh Pro/Glyph Report.txt", missingGlyphReport);
+ AssetDatabase.Refresh();
+ }
//GUIUtility.systemCopyBuffer = missingGlyphReport;
}
@@ -854,28 +977,88 @@ void UpdateRenderFeedbackWindow()
void CreateFontTexture()
{
- m_font_Atlas = new Texture2D(font_atlas_width, font_atlas_height, TextureFormat.Alpha8, false, true);
+ m_Font_Atlas = new Texture2D(m_AtlasWidth, m_AtlasHeight, TextureFormat.Alpha8, false, true);
- Color32[] colors = new Color32[font_atlas_width * font_atlas_height];
+ Color32[] colors = new Color32[m_AtlasWidth * m_AtlasHeight];
- for (int i = 0; i < (font_atlas_width * font_atlas_height); i++)
+ for (int i = 0; i < (m_AtlasWidth * m_AtlasHeight); i++)
{
byte c = m_texture_buffer[i];
colors[i] = new Color32(c, c, c, c);
}
+ // Clear allocation of
+ m_texture_buffer = null;
- if (font_renderMode == RenderModes.RasterHinted)
- m_font_Atlas.filterMode = FilterMode.Point;
+ if (m_RenderMode == RenderModes.Raster || m_RenderMode == RenderModes.RasterHinted)
+ m_Font_Atlas.filterMode = FilterMode.Point;
- m_font_Atlas.SetPixels32(colors, 0);
- m_font_Atlas.Apply(false, true);
+ m_Font_Atlas.SetPixels32(colors, 0);
+ m_Font_Atlas.Apply(false, true);
// Saving File for Debug
//var pngData = m_font_Atlas.EncodeToPNG();
//File.WriteAllBytes("Assets/Textures/Debug Font Texture.png", pngData);
- UpdateEditorWindowSize(m_font_Atlas.width, m_font_Atlas.height);
- //previewSelection = PreviewSelectionTypes.PreviewFont;
+ UpdateEditorWindowSize(m_Font_Atlas.width, m_Font_Atlas.height);
+ }
+
+
+ ///
+ /// Open Save Dialog to provide the option save the font asset using the name of the source font file. This also appends SDF to the name if using any of the SDF Font Asset creation modes.
+ ///
+ ///
+ void SaveNewFontAsset(Object sourceObject)
+ {
+ string filePath;
+
+ // Save new Font Asset and open save file requester at Source Font File location.
+ string saveDirectory = new FileInfo(AssetDatabase.GetAssetPath(sourceObject)).DirectoryName;
+
+ if (m_RenderMode < RenderModes.DistanceField16) // ((int)m_RenderMode & 0x10) == 0x10)
+ {
+ filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", saveDirectory, sourceObject.name, "asset");
+
+ if (filePath.Length == 0)
+ return;
+
+ Save_Normal_FontAsset(filePath);
+ }
+ else if (m_RenderMode >= RenderModes.DistanceField16) // ((RasterModes)m_RenderMode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || m_RenderMode == RenderModes.DistanceFieldAA)
+ {
+ filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", saveDirectory, sourceObject.name + " SDF", "asset");
+
+ if (filePath.Length == 0)
+ return;
+
+ Save_SDF_FontAsset(filePath);
+ }
+ }
+
+
+ ///
+ /// Open Save Dialog to provide the option to save the font asset under the same name.
+ ///
+ ///
+ void SaveNewFontAssetWithSameName(Object sourceObject)
+ {
+ string filePath;
+
+ // Save new Font Asset and open save file requester at Source Font File location.
+ string saveDirectory = new FileInfo(AssetDatabase.GetAssetPath(sourceObject)).DirectoryName;
+
+ filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", saveDirectory, sourceObject.name, "asset");
+
+ if (filePath.Length == 0)
+ return;
+
+ if (m_RenderMode < RenderModes.DistanceField16) // ((int)m_RenderMode & 0x10) == 0x10)
+ {
+ Save_Normal_FontAsset(filePath);
+ }
+ else if (m_RenderMode >= RenderModes.DistanceField16) // ((RasterModes)m_RenderMode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || m_RenderMode == RenderModes.DistanceFieldAA)
+ {
+ Save_SDF_FontAsset(filePath);
+ }
}
@@ -897,112 +1080,117 @@ void Save_Normal_FontAsset(string filePath)
string tex_Path_NoExt = tex_DirName + "/" + tex_FileName;
// Check if TextMeshPro font asset already exists. If not, create a new one. Otherwise update the existing one.
- TMP_FontAsset font_asset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset", typeof(TMP_FontAsset)) as TMP_FontAsset;
- if (font_asset == null)
+ TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset", typeof(TMP_FontAsset)) as TMP_FontAsset;
+ if (fontAsset == null)
{
//Debug.Log("Creating TextMeshPro font asset!");
- font_asset = ScriptableObject.CreateInstance(); // Create new TextMeshPro Font Asset.
- AssetDatabase.CreateAsset(font_asset, tex_Path_NoExt + ".asset");
+ fontAsset = ScriptableObject.CreateInstance(); // Create new TextMeshPro Font Asset.
+ AssetDatabase.CreateAsset(fontAsset, tex_Path_NoExt + ".asset");
//Set Font Asset Type
- font_asset.fontAssetType = TMP_FontAsset.FontAssetTypes.Bitmap;
+ fontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.Bitmap;
// Reference to the source font file
//font_asset.sourceFontFile = font_TTF as Font;
// Add FaceInfo to Font Asset
FaceInfo face = GetFaceInfo(m_font_faceInfo, 1);
- font_asset.AddFaceInfo(face);
+ fontAsset.AddFaceInfo(face);
// Add GlyphInfo[] to Font Asset
TMP_Glyph[] glyphs = GetGlyphInfo(m_font_glyphInfo, 1);
- font_asset.AddGlyphInfo(glyphs);
+ fontAsset.AddGlyphInfo(glyphs);
// Get and Add Kerning Pairs to Font Asset
if (includeKerningPairs)
{
- string fontFilePath = AssetDatabase.GetAssetPath(font_TTF);
+ string fontFilePath = AssetDatabase.GetAssetPath(m_SourceFontFile);
KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize);
- font_asset.AddKerningInfo(kerningTable);
+ fontAsset.AddKerningInfo(kerningTable);
}
// Add Font Atlas as Sub-Asset
- font_asset.atlas = m_font_Atlas;
- m_font_Atlas.name = tex_FileName + " Atlas";
+ fontAsset.atlas = m_Font_Atlas;
+ m_Font_Atlas.name = tex_FileName + " Atlas";
- AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset);
+ AssetDatabase.AddObjectToAsset(m_Font_Atlas, fontAsset);
// Create new Material and Add it as Sub-Asset
Shader default_Shader = Shader.Find("TextMeshPro/Bitmap"); // m_shaderSelection;
Material tmp_material = new Material(default_Shader);
tmp_material.name = tex_FileName + " Material";
- tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
- font_asset.material = tmp_material;
+ tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_Font_Atlas);
+ fontAsset.material = tmp_material;
- AssetDatabase.AddObjectToAsset(tmp_material, font_asset);
+ AssetDatabase.AddObjectToAsset(tmp_material, fontAsset);
}
else
{
// Find all Materials referencing this font atlas.
- Material[] material_references = TMP_EditorUtility.FindMaterialReferences(font_asset);
+ Material[] material_references = TMP_EditorUtility.FindMaterialReferences(fontAsset);
// Destroy Assets that will be replaced.
- DestroyImmediate(font_asset.atlas, true);
+ DestroyImmediate(fontAsset.atlas, true);
//Set Font Asset Type
- font_asset.fontAssetType = TMP_FontAsset.FontAssetTypes.Bitmap;
+ fontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.Bitmap;
// Add FaceInfo to Font Asset
FaceInfo face = GetFaceInfo(m_font_faceInfo, 1);
- font_asset.AddFaceInfo(face);
+ fontAsset.AddFaceInfo(face);
// Add GlyphInfo[] to Font Asset
TMP_Glyph[] glyphs = GetGlyphInfo(m_font_glyphInfo, 1);
- font_asset.AddGlyphInfo(glyphs);
+ fontAsset.AddGlyphInfo(glyphs);
// Get and Add Kerning Pairs to Font Asset
if (includeKerningPairs)
{
- string fontFilePath = AssetDatabase.GetAssetPath(font_TTF);
+ string fontFilePath = AssetDatabase.GetAssetPath(m_SourceFontFile);
KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize);
- font_asset.AddKerningInfo(kerningTable);
+ fontAsset.AddKerningInfo(kerningTable);
}
// Add Font Atlas as Sub-Asset
- font_asset.atlas = m_font_Atlas;
- m_font_Atlas.name = tex_FileName + " Atlas";
+ fontAsset.atlas = m_Font_Atlas;
+ m_Font_Atlas.name = tex_FileName + " Atlas";
// Special handling due to a bug in earlier versions of Unity.
- m_font_Atlas.hideFlags = HideFlags.None;
- font_asset.material.hideFlags = HideFlags.None;
+ m_Font_Atlas.hideFlags = HideFlags.None;
+ fontAsset.material.hideFlags = HideFlags.None;
- AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset);
+ AssetDatabase.AddObjectToAsset(m_Font_Atlas, fontAsset);
// Assign new font atlas texture to the existing material.
- font_asset.material.SetTexture(ShaderUtilities.ID_MainTex, font_asset.atlas);
+ fontAsset.material.SetTexture(ShaderUtilities.ID_MainTex, fontAsset.atlas);
// Update the Texture reference on the Material
for (int i = 0; i < material_references.Length; i++)
{
- material_references[i].SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
+ material_references[i].SetTexture(ShaderUtilities.ID_MainTex, m_Font_Atlas);
}
}
+ // Save Font Asset creation settings
+ m_SelectedFontAsset = fontAsset;
+ m_LegacyFontAsset = null;
+ fontAsset.creationSettings = SaveFontCreationSettings();
+
AssetDatabase.SaveAssets();
- AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(font_asset)); // Re-import font asset to get the new updated version.
+ AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(fontAsset)); // Re-import font asset to get the new updated version.
//EditorUtility.SetDirty(font_asset);
- font_asset.ReadFontDefinition();
+ fontAsset.ReadFontDefinition();
AssetDatabase.Refresh();
- m_font_Atlas = null;
+ m_Font_Atlas = null;
// NEED TO GENERATE AN EVENT TO FORCE A REDRAW OF ANY TEXTMESHPRO INSTANCES THAT MIGHT BE USING THIS FONT ASSET
- TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, font_asset);
+ TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
}
@@ -1025,39 +1213,39 @@ void Save_SDF_FontAsset(string filePath)
// Check if TextMeshPro font asset already exists. If not, create a new one. Otherwise update the existing one.
- TMP_FontAsset font_asset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset", typeof(TMP_FontAsset)) as TMP_FontAsset;
- if (font_asset == null)
+ TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset");
+ if (fontAsset == null)
{
//Debug.Log("Creating TextMeshPro font asset!");
- font_asset = ScriptableObject.CreateInstance(); // Create new TextMeshPro Font Asset.
- AssetDatabase.CreateAsset(font_asset, tex_Path_NoExt + ".asset");
+ fontAsset = ScriptableObject.CreateInstance(); // Create new TextMeshPro Font Asset.
+ AssetDatabase.CreateAsset(fontAsset, tex_Path_NoExt + ".asset");
// Reference to the source font file
//font_asset.sourceFontFile = font_TTF as Font;
//Set Font Asset Type
- font_asset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
+ fontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
//if (m_destination_Atlas != null)
// m_font_Atlas = m_destination_Atlas;
// If using the C# SDF creation mode, we need the scale down factor.
- int scaleDownFactor = font_renderMode >= RenderModes.DistanceField16 ? 1 : font_scaledownFactor;
+ int scaleDownFactor = 1; // ((RasterModes)m_RenderMode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || m_RenderMode == RenderModes.DistanceFieldAA ? 1 : font_scaledownFactor;
// Add FaceInfo to Font Asset
FaceInfo face = GetFaceInfo(m_font_faceInfo, scaleDownFactor);
- font_asset.AddFaceInfo(face);
+ fontAsset.AddFaceInfo(face);
// Add GlyphInfo[] to Font Asset
TMP_Glyph[] glyphs = GetGlyphInfo(m_font_glyphInfo, scaleDownFactor);
- font_asset.AddGlyphInfo(glyphs);
+ fontAsset.AddGlyphInfo(glyphs);
// Get and Add Kerning Pairs to Font Asset
if (includeKerningPairs)
{
- string fontFilePath = AssetDatabase.GetAssetPath(font_TTF);
+ string fontFilePath = AssetDatabase.GetAssetPath(m_SourceFontFile);
KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize);
- font_asset.AddKerningInfo(kerningTable);
+ fontAsset.AddKerningInfo(kerningTable);
}
// Add Line Breaking Rules
@@ -1065,127 +1253,193 @@ void Save_SDF_FontAsset(string filePath)
//
// Add Font Atlas as Sub-Asset
- font_asset.atlas = m_font_Atlas;
- m_font_Atlas.name = tex_FileName + " Atlas";
+ fontAsset.atlas = m_Font_Atlas;
+ m_Font_Atlas.name = tex_FileName + " Atlas";
- AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset);
+ AssetDatabase.AddObjectToAsset(m_Font_Atlas, fontAsset);
// Create new Material and Add it as Sub-Asset
Shader default_Shader = Shader.Find("TextMeshPro/Distance Field"); //m_shaderSelection;
Material tmp_material = new Material(default_Shader);
tmp_material.name = tex_FileName + " Material";
- tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width);
- tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height);
+ tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_Font_Atlas);
+ tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, m_Font_Atlas.width);
+ tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, m_Font_Atlas.height);
- int spread = font_padding + 1;
+ int spread = m_Padding + 1;
tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, spread); // Spread = Padding for Brute Force SDF.
- tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, font_asset.normalStyle);
- tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, font_asset.boldStyle);
+ tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
+ tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
- font_asset.material = tmp_material;
+ fontAsset.material = tmp_material;
- AssetDatabase.AddObjectToAsset(tmp_material, font_asset);
+ AssetDatabase.AddObjectToAsset(tmp_material, fontAsset);
}
else
{
// Find all Materials referencing this font atlas.
- Material[] material_references = TMP_EditorUtility.FindMaterialReferences(font_asset);
+ Material[] material_references = TMP_EditorUtility.FindMaterialReferences(fontAsset);
// Destroy Assets that will be replaced.
- DestroyImmediate(font_asset.atlas, true);
+ DestroyImmediate(fontAsset.atlas, true);
//Set Font Asset Type
- font_asset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
+ fontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
- int scaleDownFactor = font_renderMode >= RenderModes.DistanceField16 ? 1 : font_scaledownFactor;
+ int scaleDownFactor = 1; // ((RasterModes)m_RenderMode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || m_RenderMode == RenderModes.DistanceFieldAA ? 1 : font_scaledownFactor;
// Add FaceInfo to Font Asset
FaceInfo face = GetFaceInfo(m_font_faceInfo, scaleDownFactor);
- font_asset.AddFaceInfo(face);
+ fontAsset.AddFaceInfo(face);
// Add GlyphInfo[] to Font Asset
TMP_Glyph[] glyphs = GetGlyphInfo(m_font_glyphInfo, scaleDownFactor);
- font_asset.AddGlyphInfo(glyphs);
+ fontAsset.AddGlyphInfo(glyphs);
// Get and Add Kerning Pairs to Font Asset
if (includeKerningPairs)
{
- string fontFilePath = AssetDatabase.GetAssetPath(font_TTF);
+ string fontFilePath = AssetDatabase.GetAssetPath(m_SourceFontFile);
KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize);
- font_asset.AddKerningInfo(kerningTable);
+ fontAsset.AddKerningInfo(kerningTable);
}
// Add Font Atlas as Sub-Asset
- font_asset.atlas = m_font_Atlas;
- m_font_Atlas.name = tex_FileName + " Atlas";
+ fontAsset.atlas = m_Font_Atlas;
+ m_Font_Atlas.name = tex_FileName + " Atlas";
// Special handling due to a bug in earlier versions of Unity.
- m_font_Atlas.hideFlags = HideFlags.None;
- font_asset.material.hideFlags = HideFlags.None;
+ m_Font_Atlas.hideFlags = HideFlags.None;
+ fontAsset.material.hideFlags = HideFlags.None;
- AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset);
+ AssetDatabase.AddObjectToAsset(m_Font_Atlas, fontAsset);
// Assign new font atlas texture to the existing material.
- font_asset.material.SetTexture(ShaderUtilities.ID_MainTex, font_asset.atlas);
+ fontAsset.material.SetTexture(ShaderUtilities.ID_MainTex, fontAsset.atlas);
// Update the Texture reference on the Material
for (int i = 0; i < material_references.Length; i++)
{
- material_references[i].SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
- material_references[i].SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width);
- material_references[i].SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height);
+ material_references[i].SetTexture(ShaderUtilities.ID_MainTex, m_Font_Atlas);
+ material_references[i].SetFloat(ShaderUtilities.ID_TextureWidth, m_Font_Atlas.width);
+ material_references[i].SetFloat(ShaderUtilities.ID_TextureHeight, m_Font_Atlas.height);
- int spread = font_padding + 1;
+ int spread = m_Padding + 1;
material_references[i].SetFloat(ShaderUtilities.ID_GradientScale, spread); // Spread = Padding for Brute Force SDF.
- material_references[i].SetFloat(ShaderUtilities.ID_WeightNormal, font_asset.normalStyle);
- material_references[i].SetFloat(ShaderUtilities.ID_WeightBold, font_asset.boldStyle);
+ material_references[i].SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
+ material_references[i].SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
}
}
// Saving File for Debug
//var pngData = destination_Atlas.EncodeToPNG();
- //File.WriteAllBytes("Assets/Textures/Debug Distance Field.png", pngData);
- //font_asset.fontCreationSettings = SaveFontCreationSettings();
+ //File.WriteAllBytes("Assets/Textures/Debug Distance Field.png", pngData);
+
+ // Save Font Asset creation settings
+ m_SelectedFontAsset = fontAsset;
+ m_LegacyFontAsset = null;
+ fontAsset.creationSettings = SaveFontCreationSettings();
AssetDatabase.SaveAssets();
- AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(font_asset)); // Re-import font asset to get the new updated version.
+ AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(fontAsset)); // Re-import font asset to get the new updated version.
- font_asset.ReadFontDefinition();
+ fontAsset.ReadFontDefinition();
AssetDatabase.Refresh();
- m_font_Atlas = null;
+ m_Font_Atlas = null;
// NEED TO GENERATE AN EVENT TO FORCE A REDRAW OF ANY TEXTMESHPRO INSTANCES THAT MIGHT BE USING THIS FONT ASSET
- TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, font_asset);
+ TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
}
- FontCreationSetting SaveFontCreationSettings()
+ ///
+ /// Internal method to save the Font Asset Creation Settings
+ ///
+ ///
+ FontAssetCreationSettings SaveFontCreationSettings()
{
- FontCreationSetting settings = new FontCreationSetting();
- settings.fontSourcePath = AssetDatabase.GetAssetPath(font_TTF);
- settings.fontSizingMode = FontSizingOption_Selection;
- settings.fontSize = font_size;
- settings.fontPadding = font_padding;
- settings.fontPackingMode = (int)m_fontPackingSelection;
- settings.fontAtlasWidth = font_atlas_width;
- settings.fontAtlasHeight = font_atlas_height;
- settings.fontCharacterSet = font_CharacterSet_Selection;
- settings.fontStyle = (int)font_style;
- settings.fontStlyeModifier = font_style_mod;
- settings.fontRenderMode = (int)font_renderMode;
- settings.fontKerning = includeKerningPairs;
+ FontAssetCreationSettings settings = new FontAssetCreationSettings();
+
+ //settings.sourceFontFileName = m_SourceFontFile.name;
+ settings.sourceFontFileGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_SourceFontFile));
+ settings.pointSizeSamplingMode = m_PointSizeSamplingMode;
+ settings.pointSize = m_PointSize;
+ settings.padding = m_Padding;
+ settings.packingMode = (int)m_PackingMode;
+ settings.atlasWidth = m_AtlasWidth;
+ settings.atlasHeight = m_AtlasHeight;
+ settings.characterSetSelectionMode = m_CharacterSetSelectionMode;
+ settings.characterSequence = m_CharacterSequence;
+ settings.referencedFontAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_ReferencedFontAsset));
+ settings.referencedTextAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_CharactersFromFile));
+ settings.fontStyle = (int)m_FontStyle;
+ settings.fontStyleModifier = m_FontStyleValue;
+ settings.renderMode = (int)m_RenderMode;
+ settings.includeFontFeatures = includeKerningPairs;
return settings;
}
+ ///
+ /// Internal method to load the Font Asset Creation Settings
+ ///
+ ///
+ void LoadFontCreationSettings(FontAssetCreationSettings settings)
+ {
+ m_SourceFontFile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(settings.sourceFontFileGUID));
+ m_PointSizeSamplingMode = settings.pointSizeSamplingMode;
+ m_PointSize = settings.pointSize;
+ m_Padding = settings.padding;
+ m_PackingMode = (FontPackingModes)settings.packingMode;
+ m_AtlasWidth = settings.atlasWidth;
+ m_AtlasHeight = settings.atlasHeight;
+ m_CharacterSetSelectionMode = settings.characterSetSelectionMode;
+ m_CharacterSequence = settings.characterSequence;
+ m_ReferencedFontAsset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(settings.referencedFontAssetGUID));
+ m_CharactersFromFile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(settings.referencedTextAssetGUID));
+ m_FontStyle = (FaceStyles)settings.fontStyle;
+ m_FontStyleValue = settings.fontStyleModifier;
+ m_RenderMode = (RenderModes)settings.renderMode;
+ includeKerningPairs = settings.includeFontFeatures;
+ }
+
+
+ ///
+ /// Save the latest font asset creation settings to EditorPrefs.
+ ///
+ ///
+ void SaveCreationSettingsToEditorPrefs(FontAssetCreationSettings settings)
+ {
+ // Create new list if one does not already exist
+ if (m_FontAssetCreationSettingsContainer == null)
+ {
+ m_FontAssetCreationSettingsContainer = new FontAssetCreationSettingsContainer();
+ m_FontAssetCreationSettingsContainer.fontAssetCreationSettings = new List();
+ }
+
+ // Add new creation settings to the list
+ m_FontAssetCreationSettingsContainer.fontAssetCreationSettings.Add(settings);
+
+ // Since list should only contain the most 4 recent settings, we remove the first element if list exceeds 4 elements.
+ if (m_FontAssetCreationSettingsContainer.fontAssetCreationSettings.Count > 4)
+ m_FontAssetCreationSettingsContainer.fontAssetCreationSettings.RemoveAt(0);
+
+ m_FontAssetCreationSettingsCurrentIndex = m_FontAssetCreationSettingsContainer.fontAssetCreationSettings.Count - 1;
+
+ // Serialize list to JSON
+ string serializedSettings = JsonUtility.ToJson(m_FontAssetCreationSettingsContainer, true);
+
+ EditorPrefs.SetString(k_FontAssetCreationSettingsContainerKey, serializedSettings);
+ }
+
+
void UpdateEditorWindowSize(float width, float height)
{
@@ -1221,9 +1475,13 @@ void DrawPreview()
//{
// GUI.DrawTexture(new Rect(pixelRect.x, pixelRect.y, m_previewWindow_Size.x, m_previewWindow_Size.y), m_texture_Atlas, ScaleMode.ScaleToFit);
//}
- else if (m_font_Atlas != null && previewSelection == PreviewSelectionTypes.PreviewFont)
+ else if (m_Font_Atlas != null && previewSelection == PreviewSelectionTypes.PreviewFont)
+ {
+ EditorGUI.DrawTextureAlpha(new Rect(pixelRect.x, pixelRect.y, m_previewWindow_Size.x, m_previewWindow_Size.y), m_Font_Atlas, ScaleMode.ScaleToFit);
+ }
+ else if (m_SavedFontAtlas != null && previewSelection == PreviewSelectionTypes.PreviewFont)
{
- EditorGUI.DrawTextureAlpha(new Rect(pixelRect.x, pixelRect.y, m_previewWindow_Size.x, m_previewWindow_Size.y), m_font_Atlas, ScaleMode.ScaleToFit);
+ EditorGUI.DrawTextureAlpha(new Rect(pixelRect.x, pixelRect.y, m_previewWindow_Size.x, m_previewWindow_Size.y), m_SavedFontAtlas, ScaleMode.ScaleToFit);
}
GUILayout.EndVertical();
@@ -1327,7 +1585,7 @@ private string[] UpdateShaderList(RenderModes mode, out Shader[] shaders)
// Get shaders for the given RenderModes.
string searchPattern = "t:Shader" + " TMP_"; // + fontAsset.name.Split(new char[] { ' ' })[0];
- if (mode == RenderModes.DistanceField16 || mode == RenderModes.DistanceField32)
+ if (mode >= RenderModes.DistanceField16) // ((RasterModes)mode & RasterModes.Raster_Mode_SDF) == RasterModes.Raster_Mode_SDF || mode == RenderModes.DistanceFieldAA)
searchPattern += " SDF";
else
searchPattern += " Bitmap";
diff --git a/Scripts/Runtime/TMP_FontAsset.cs b/Scripts/Runtime/TMP_FontAsset.cs
index e3c5da4..52d2e15 100644
--- a/Scripts/Runtime/TMP_FontAsset.cs
+++ b/Scripts/Runtime/TMP_FontAsset.cs
@@ -101,15 +101,23 @@ public KerningTable kerningInfo
///
- /// List which contains the Fallback font assets for this font.
+ /// List containing the Fallback font assets for this font.
///
[SerializeField]
public List fallbackFontAssets;
-
- // TODO : Not implemented yet.
+ #if UNITY_EDITOR
+ ///
+ /// The settings used in the Font Asset Creator when this font asset was created or edited.
+ ///
+ public FontAssetCreationSettings creationSettings
+ {
+ get { return m_CreationSettings; }
+ set { m_CreationSettings = value; }
+ }
[SerializeField]
- public FontCreationSetting fontCreationSettings;
+ public FontAssetCreationSettings m_CreationSettings;
+ #endif
// FONT WEIGHTS
[SerializeField]
@@ -127,7 +135,6 @@ public KerningTable kerningInfo
private byte m_oldTabSize;
-
void OnEnable()
{
//Debug.Log("OnEnable has been called on " + this.name);
diff --git a/Scripts/Runtime/TMP_InputField.cs b/Scripts/Runtime/TMP_InputField.cs
index 4d372a6..a83d7f0 100644
--- a/Scripts/Runtime/TMP_InputField.cs
+++ b/Scripts/Runtime/TMP_InputField.cs
@@ -1,4 +1,4 @@
-//#define DEBUG_MODE
+//#define TMP_DEBUG_MODE
using System;
using System.Collections;
@@ -1699,7 +1699,7 @@ private void MoveRight(bool shift, bool ctrl)
stringPositionInternal = stringSelectPositionInternal = Mathf.Max(stringPositionInternal, stringSelectPositionInternal);
caretPositionInternal = caretSelectPositionInternal = GetCaretPositionFromStringIndex(stringSelectPositionInternal);
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
return;
@@ -1728,7 +1728,7 @@ private void MoveRight(bool shift, bool ctrl)
caretSelectPositionInternal = caretPositionInternal = GetCaretPositionFromStringIndex(stringSelectPositionInternal);
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -1757,7 +1757,7 @@ private void MoveLeft(bool shift, bool ctrl)
stringPositionInternal = stringSelectPositionInternal = Mathf.Min(stringPositionInternal, stringSelectPositionInternal);
caretPositionInternal = caretSelectPositionInternal = GetCaretPositionFromStringIndex(stringSelectPositionInternal);
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
return;
@@ -1786,7 +1786,7 @@ private void MoveLeft(bool shift, bool ctrl)
caretSelectPositionInternal = caretPositionInternal = GetCaretPositionFromStringIndex(stringSelectPositionInternal);
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2056,7 +2056,7 @@ private void MoveDown(bool shift, bool goToLastChar)
stringSelectPositionInternal = stringPositionInternal = GetStringIndexFromCaretPosition(caretSelectPositionInternal);
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2089,7 +2089,7 @@ private void MoveUp(bool shift, bool goToFirstChar)
stringSelectPositionInternal = stringPositionInternal = GetStringIndexFromCaretPosition(caretSelectPositionInternal);
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2142,8 +2142,8 @@ private void MovePageUp(bool shift, bool goToFirstChar)
m_IsScrollbarUpdateRequired = true;
}
- #if DEBUG_MODE
- Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal + " Line: " + currentLine);
+ #if TMP_DEBUG_MODE
+ Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2195,8 +2195,8 @@ private void MovePageDown(bool shift, bool goToLastChar)
m_IsScrollbarUpdateRequired = true;
}
- #if DEBUG_MODE
- Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal + " Line: " + currentLine);
+ #if TMP_DEBUG_MODE
+ Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2248,7 +2248,7 @@ private void Delete()
}
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2289,7 +2289,7 @@ private void ForwardSpace()
}
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2337,7 +2337,7 @@ private void Backspace()
}
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
@@ -2419,7 +2419,7 @@ private void Insert(char c)
SendOnValueChanged();
- #if DEBUG_MODE
+ #if TMP_DEBUG_MODE
Debug.Log("Caret Position: " + caretPositionInternal + " Selection Position: " + caretSelectPositionInternal + " String Position: " + stringPositionInternal + " String Select Position: " + stringSelectPositionInternal);
#endif
}
diff --git a/Scripts/Runtime/TMP_Settings.cs b/Scripts/Runtime/TMP_Settings.cs
index 1f46901..b6929f6 100644
--- a/Scripts/Runtime/TMP_Settings.cs
+++ b/Scripts/Runtime/TMP_Settings.cs
@@ -18,7 +18,7 @@ public class TMP_Settings : ScriptableObject
///
public static string version
{
- get { return "1.2.2"; }
+ get { return "1.2.3"; }
}
///
diff --git a/Scripts/Runtime/TMP_Text.cs b/Scripts/Runtime/TMP_Text.cs
index 21e7e6d..9cbdf16 100644
--- a/Scripts/Runtime/TMP_Text.cs
+++ b/Scripts/Runtime/TMP_Text.cs
@@ -3754,12 +3754,6 @@ protected virtual Vector2 CalculatePreferredValues(float defaultFontSize, Vector
for (int i = 0; m_char_buffer[i] != 0; i++)
{
charCode = m_char_buffer[i];
- m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
-
- m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
- m_currentFontAsset = m_materialReferences[m_currentMaterialIndex].fontAsset;
-
- int prev_MaterialIndex = m_currentMaterialIndex;
// Parse Rich Text Tag
#region Parse Rich Text Tag
@@ -3778,12 +3772,19 @@ protected virtual Vector2 CalculatePreferredValues(float defaultFontSize, Vector
continue;
}
}
+ else
+ {
+ m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
+ m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
+ m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
+ }
#endregion End Parse Rich Text Tag
- m_isParsingText = false;
-
+ int prev_MaterialIndex = m_currentMaterialIndex;
bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
+ m_isParsingText = false;
+
// Handle Font Styles like LowerCase, UpperCase and SmallCaps.
#region Handling of LowerCase, UpperCase and SmallCaps Font Styles
diff --git a/Scripts/Runtime/TMPro_FontUtilities.cs b/Scripts/Runtime/TMPro_FontUtilities.cs
index e23d2fd..5958c55 100644
--- a/Scripts/Runtime/TMPro_FontUtilities.cs
+++ b/Scripts/Runtime/TMPro_FontUtilities.cs
@@ -75,22 +75,27 @@ public static TMP_Glyph Clone(TMP_Glyph source)
// Structure which holds the font creation settings
[Serializable]
- public struct FontCreationSetting
+ public struct FontAssetCreationSettings
{
- public string fontSourcePath;
- public int fontSizingMode;
- public int fontSize;
- public int fontPadding;
- public int fontPackingMode;
- public int fontAtlasWidth;
- public int fontAtlasHeight;
- public int fontCharacterSet;
+ public string sourceFontFileName;
+ public string sourceFontFileGUID;
+ public int pointSizeSamplingMode;
+ public int pointSize;
+ public int padding;
+ public int packingMode;
+ public int atlasWidth;
+ public int atlasHeight;
+ public int characterSetSelectionMode;
+ public string characterSequence;
+ public string referencedFontAssetGUID;
+ public string referencedTextAssetGUID;
public int fontStyle;
- public float fontStlyeModifier;
- public int fontRenderMode;
- public bool fontKerning;
+ public float fontStyleModifier;
+ public int renderMode;
+ public bool includeFontFeatures;
}
+
public struct KerningPairKey
{
public uint ascii_Left;
diff --git a/Scripts/Runtime/TMPro_Private.cs b/Scripts/Runtime/TMPro_Private.cs
index de697ba..02374a5 100644
--- a/Scripts/Runtime/TMPro_Private.cs
+++ b/Scripts/Runtime/TMPro_Private.cs
@@ -1494,7 +1494,7 @@ void OnPreRenderObject()
{
//Debug.Log("*** OnPreRenderObject() ***");
- if (!m_isAwake || !m_ignoreActiveState && !this.IsActive()) return;
+ if (!m_isAwake || (this.IsActive() == false && m_ignoreActiveState == false)) return;
// Debug Variables
loopCountA = 0;
@@ -1733,11 +1733,6 @@ protected override void GenerateTextMesh()
for (int i = 0; i < m_char_buffer.Length && m_char_buffer[i] != 0; i++)
{
charCode = m_char_buffer[i];
- m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
- m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
- m_currentFontAsset = m_materialReferences[m_currentMaterialIndex].fontAsset;
-
- int prev_MaterialIndex = m_currentMaterialIndex;
// Parse Rich Text Tag
#region Parse Rich Text Tag
@@ -1756,12 +1751,19 @@ protected override void GenerateTextMesh()
continue;
}
}
+ else
+ {
+ m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
+ m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
+ m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
+ }
#endregion End Parse Rich Text Tag
- m_isParsingText = false;
-
+ int prev_MaterialIndex = m_currentMaterialIndex;
bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
+ m_isParsingText = false;
+
// When using Linked text, mark character as ignored and skip to next character.
if (m_characterCount < m_firstVisibleCharacter)
{
@@ -1821,11 +1823,9 @@ protected override void GenerateTextMesh()
else
m_spriteColor = s_colorWhite;
- m_currentFontAsset = m_fontAsset;
-
// The sprite scale calculations are based on the font asset assigned to the text object.
- float spriteScale = (m_currentFontSize / m_fontAsset.fontInfo.PointSize * m_fontAsset.fontInfo.Scale * (m_isOrthographic ? 1 : 0.1f));
- currentElementScale = m_fontAsset.fontInfo.Ascender / sprite.height * sprite.scale * spriteScale;
+ float spriteScale = (m_currentFontSize / m_currentFontAsset.fontInfo.PointSize * m_currentFontAsset.fontInfo.Scale * (m_isOrthographic ? 1 : 0.1f));
+ currentElementScale = m_currentFontAsset.fontInfo.Ascender / sprite.height * sprite.scale * spriteScale;
m_cached_TextElement = sprite;
@@ -1975,10 +1975,10 @@ protected override void GenerateTextMesh()
// Determine the position of the vertices of the Character or Sprite.
#region Calculate Vertices Position
- float fontBaseLineOffset = m_currentFontAsset.fontInfo.Baseline;
+ float fontBaseLineOffset = m_currentFontAsset.fontInfo.Baseline * m_fontScale * m_fontScaleMultiplier * m_currentFontAsset.fontInfo.Scale;
Vector3 top_left;
top_left.x = m_xAdvance + ((m_cached_TextElement.xOffset - padding - style_padding + glyphAdjustments.xPlacement) * currentElementScale * (1 - m_charWidthAdjDelta));
- top_left.y = (fontBaseLineOffset + m_cached_TextElement.yOffset + padding + glyphAdjustments.yPlacement) * currentElementScale - m_lineOffset + m_baselineOffset;
+ top_left.y = fontBaseLineOffset + (m_cached_TextElement.yOffset + padding + glyphAdjustments.yPlacement) * currentElementScale - m_lineOffset + m_baselineOffset;
top_left.z = 0;
Vector3 bottom_left;
@@ -2045,7 +2045,7 @@ protected override void GenerateTextMesh()
m_textInfo.characterInfo[m_characterCount].bottomRight = bottom_right;
m_textInfo.characterInfo[m_characterCount].origin = m_xAdvance;
- m_textInfo.characterInfo[m_characterCount].baseLine = 0 - m_lineOffset + m_baselineOffset;
+ m_textInfo.characterInfo[m_characterCount].baseLine = fontBaseLineOffset - m_lineOffset + m_baselineOffset;
m_textInfo.characterInfo[m_characterCount].aspectRatio = (top_right.x - bottom_left.x) / (top_left.y - bottom_left.y);
@@ -3780,7 +3780,7 @@ protected override void GenerateTextMesh()
////Profiler.BeginSample("TMP Generate Text - Phase III");
// Update Mesh Vertex Data
- if (m_renderMode == TextRenderFlags.Render)
+ if (m_renderMode == TextRenderFlags.Render && IsActive())
{
// Clear unused vertices
//m_textInfo.meshInfo[0].ClearUnusedVertices();
diff --git a/Scripts/Runtime/TMPro_ShaderUtilities.cs b/Scripts/Runtime/TMPro_ShaderUtilities.cs
index 29e246c..67bba95 100644
--- a/Scripts/Runtime/TMPro_ShaderUtilities.cs
+++ b/Scripts/Runtime/TMPro_ShaderUtilities.cs
@@ -28,7 +28,8 @@ public static class ShaderUtilities
public static int ID_OutlineWidth;
public static int ID_OutlineSoftness;
public static int ID_OutlineColor;
-
+
+ public static int ID_Padding;
public static int ID_GradientScale;
public static int ID_ScaleX;
public static int ID_ScaleY;
@@ -126,6 +127,7 @@ public static void GetShaderPropertyIDs()
ID_OutlineSoftness = Shader.PropertyToID("_OutlineSoftness");
ID_OutlineColor = Shader.PropertyToID("_OutlineColor");
+ ID_Padding = Shader.PropertyToID("_Padding");
ID_GradientScale = Shader.PropertyToID("_GradientScale");
ID_ScaleX = Shader.PropertyToID("_ScaleX");
ID_ScaleY = Shader.PropertyToID("_ScaleY");
@@ -290,8 +292,14 @@ public static float GetPadding(Material material, bool enableExtraPadding, bool
int extraPadding = enableExtraPadding ? 4 : 0;
- if (!material.HasProperty(ID_GradientScale))
- return extraPadding; // We are using an non SDF Shader.
+ // Check if we are using a non Distance Field Shader
+ if (material.HasProperty(ID_GradientScale) == false)
+ {
+ if (material.HasProperty(ID_Padding))
+ extraPadding += (int)material.GetFloat(ID_Padding);
+
+ return extraPadding;
+ }
Vector4 padding = Vector4.zero;
Vector4 maxPadding = Vector4.zero;
@@ -405,10 +413,11 @@ public static float GetPadding(Material[] materials, bool enableExtraPadding, bo
// Return if Material is null
if (materials == null) return 0;
- int extraPadding = enableExtraPadding ? 4 : 0;
+ int extraPadding = enableExtraPadding ? 4 : 0;
- if (!materials[0].HasProperty(ShaderUtilities.ID_GradientScale))
- return extraPadding; // We are using an non SDF Shader.
+ // Check if we are using a Bitmap Shader
+ if (materials[0].HasProperty(ID_Padding))
+ return extraPadding + materials[0].GetFloat(ID_Padding);
Vector4 padding = Vector4.zero;
Vector4 maxPadding = Vector4.zero;
diff --git a/Scripts/Runtime/TMPro_UGUI_Private.cs b/Scripts/Runtime/TMPro_UGUI_Private.cs
index a9db643..beac03a 100644
--- a/Scripts/Runtime/TMPro_UGUI_Private.cs
+++ b/Scripts/Runtime/TMPro_UGUI_Private.cs
@@ -1587,7 +1587,7 @@ void OnPreRenderCanvas()
//Debug.Log("*** OnPreRenderCanvas() *** Frame: " + Time.frameCount);
// Make sure object is active and that we have a valid Canvas.
- if (!m_isAwake || !m_ignoreActiveState && !this.IsActive()) return;
+ if (!m_isAwake || (this.IsActive() == false && m_ignoreActiveState == false)) return;
if (m_canvas == null) { m_canvas = this.canvas; if (m_canvas == null) return; }
@@ -1839,11 +1839,9 @@ protected override void GenerateTextMesh()
for (int i = 0; i < m_char_buffer.Length && m_char_buffer[i] != 0; i++)
{
charCode = m_char_buffer[i];
- m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
- m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
- m_currentFontAsset = m_materialReferences[m_currentMaterialIndex].fontAsset;
+
- int prev_MaterialIndex = m_currentMaterialIndex;
+
// Parse Rich Text Tag
#region Parse Rich Text Tag
@@ -1862,12 +1860,20 @@ protected override void GenerateTextMesh()
continue;
}
}
+ else
+ {
+ m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
+ m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
+ m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
+ //m_currentFontAsset = m_materialReferences[m_currentMaterialIndex].fontAsset;
+ }
#endregion End Parse Rich Text Tag
- m_isParsingText = false;
-
+ int prev_MaterialIndex = m_currentMaterialIndex;
bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
+ m_isParsingText = false;
+
// When using Linked text, mark character as ignored and skip to next character.
if (m_characterCount < m_firstVisibleCharacter)
{
@@ -1934,11 +1940,9 @@ protected override void GenerateTextMesh()
else
m_spriteColor = s_colorWhite;
- m_currentFontAsset = m_fontAsset;
-
// The sprite scale calculations are based on the font asset assigned to the text object.
- float spriteScale = (m_currentFontSize / m_fontAsset.fontInfo.PointSize * m_fontAsset.fontInfo.Scale);
- currentElementScale = m_fontAsset.fontInfo.Ascender / sprite.height * sprite.scale * spriteScale;
+ float spriteScale = (m_currentFontSize / m_currentFontAsset.fontInfo.PointSize * m_currentFontAsset.fontInfo.Scale);
+ currentElementScale = m_currentFontAsset.fontInfo.Ascender / sprite.height * sprite.scale * spriteScale;
m_cached_TextElement = sprite;
@@ -2094,10 +2098,10 @@ protected override void GenerateTextMesh()
#if PROFILE_ON
Profiler.BeginSample("Calculate Vertices Position");
#endif
- float fontBaseLineOffset = m_currentFontAsset.fontInfo.Baseline;
+ float fontBaseLineOffset = m_currentFontAsset.fontInfo.Baseline * m_fontScale * m_fontScaleMultiplier * m_currentFontAsset.fontInfo.Scale;
Vector3 top_left;
top_left.x = m_xAdvance + ((m_cached_TextElement.xOffset - padding - style_padding + glyphAdjustments.xPlacement) * currentElementScale * (1 - m_charWidthAdjDelta));
- top_left.y = (fontBaseLineOffset + m_cached_TextElement.yOffset + padding + glyphAdjustments.yPlacement) * currentElementScale - m_lineOffset + m_baselineOffset;
+ top_left.y = fontBaseLineOffset + (m_cached_TextElement.yOffset + padding + glyphAdjustments.yPlacement) * currentElementScale - m_lineOffset + m_baselineOffset;
top_left.z = 0;
Vector3 bottom_left;
@@ -2168,7 +2172,7 @@ protected override void GenerateTextMesh()
m_textInfo.characterInfo[m_characterCount].bottomRight = bottom_right;
m_textInfo.characterInfo[m_characterCount].origin = m_xAdvance;
- m_textInfo.characterInfo[m_characterCount].baseLine = 0 - m_lineOffset + m_baselineOffset;
+ m_textInfo.characterInfo[m_characterCount].baseLine = fontBaseLineOffset - m_lineOffset + m_baselineOffset;
m_textInfo.characterInfo[m_characterCount].aspectRatio = (top_right.x - bottom_left.x) / (top_left.y - bottom_left.y);
@@ -4021,7 +4025,7 @@ protected override void GenerateTextMesh()
#if PROFILE_PHASES_ON
Profiler.BeginSample("TMP Generate Text - Phase III");
#endif
- if (m_renderMode == TextRenderFlags.Render)
+ if (m_renderMode == TextRenderFlags.Render && IsActive())
{
// Clear unused vertices
//m_textInfo.meshInfo[0].ClearUnusedVertices();
diff --git a/package.json b/package.json
index b23beb2..82496ef 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "com.unity.textmeshpro",
"displayName": "TextMesh Pro",
- "version": "1.2.2",
+ "version": "1.2.3",
"unity": "2018.1",
"description": "TextMesh Pro is the ultimate text solution for Unity. It's the perfect replacement for Unity's UI Text and the legacy Text Mesh.\n\nPowerful and easy to use, TextMesh Pro uses Advanced Text Rendering techniques along with a set of custom shaders; delivering substantial visual quality improvements while giving users incredible flexibility when it comes to text styling and texturing.\n\nTextMesh Pro provides Improved Control over text formatting and layout with features like character, word, line and paragraph spacing, kerning, justified text, Links, over 30 Rich Text Tags available, support for Multi Font & Sprites, Custom Styles and more.\n\nGreat performance. Since the geometry created by TextMesh Pro uses two triangles per character just like Unity's text components, this improved visual quality and flexibility comes at no additional performance cost.",
"keywords": [ "TextMeshPro", "TextMesh Pro", "Text", "SDF" ],