Iam looking for a way to automate lots of Font Assets and updating them from time to time.
The old way was to use the ForntPlugin
TMP_FontPlugin.Initialize_FontEngine(); …and finaly render them into the atlas
errorCode = TMPro_FontPlugin.Render_Characters(textureBuffer, atlasWidth, atlasHeight, characterPadding, characterArray, characterCount, fontStyle, strokeSize, useAutoSizing, fontRenderMode, (int)fontPackingMode, ref fontFaceInfo, fontGlyphInfo);
Now it looks like this possibility is gone.
What is left is the Window
namespace TMPro.EditorUtilities
{
public class TMPro_FontAssetCreatorWindow : EditorWindow
should we use that for doing automations?
I’ll need to make some tweaks / expose a few more API functions to provide this functionality via the new FontEngine API.
The revised Font Asset Creator has this functionality but it is more granular now. Until I find the time to expose additional API functionality, I suggest you take a look at how the Font Asset Creator is handling this since the source code for the package is available.
P.S. Currently, it is possible to create font assets at runtime and in the editor. It is also possible to add glyphs and characters to them but the auto-sizing feature isn’t exposed in those functions. Basically, I need to add a few overloads to handle this.
1 Like
Thanks a lot for the fast reply.
Hi @Stephan_B ,
Hope you’re doing OK in these crazy times.
Sorry to necro this thread almost a year after the last activity, but I am also looking to automate font asset creation in the editor.
I have attempted to replicate the “Generate Font Atlas” code from TMPro_FontAssetCreatorWindow in my own Editor scripts but have run into some issues where required functionality is marked as internal.
Can the following be made public, please?
- GlyphRasterModes enum
- FontEngine.TryPackGlyphsInAtlas
- FontEngine.RenderGlyphsToTexture
I am currently using v1.4.1 from the Package Manager, but looking at the release notes the above changes do not seem to have already been made in any of the 1.5 previews.
Thanks a lot,
Niall
3 Likes
I managed to recreate the font atlas creation using reflection
Here’s the class I created: TextMesh Pro font atlas generator ($2077829) · Snippets · GitLab
You have to set the parameters using reflection as well, here’s an example:
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_SourceFontFile", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(font));
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_CharacterSetSelectionMode", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, 8);
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_CharactersFromFile", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, AssetDatabase.LoadAssetAtPath<TextAsset>(path));
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_PackingMode", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, 4);
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_AtlasWidth", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, set.AtlasWidth);
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_AtlasHeight", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, set.AtlasHeight);
typeof(TMPro_FontAssetCreatorWindow)
.GetField("m_IncludeFontFeatures", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(window, true);
I might do a proper asset in the future
2 Likes