实际操作参考:Unity3d 教程 | TextmeshPro 动态字体 | Fallback | 后备字体 | UI_哔哩哔哩_bilibili
原文链接:TextMesh Pro: Font Asset Creation - Unity Learn
1. 引言
把Font Assets看成字体容器(font container),这样就能在项目中使用各种花里胡哨的字体,但是只需用一个相关文件,不用反复的修改原字体文件。
如果你想使用定制或者本地字体,Font Assets Creator 会把字体文件打包成 altas(字体图),也就是包含了所有基本字体元素的组织文件(Texture file)。
怎么使用Font Assets Creator:
1. 新建文件夹存放 font 文件 , font 文件你电脑就有(c盘->windows->font)。
2. 在 UNITY IDE 中点击 Window -> TextMeshPro -> Fon Asset Creator , 点击后出现如下窗口。
然后,把 font 文件拖拽到 Source Font File 。点击 Genrate Font Atlas , 生成好后会出现黑底白字的 Font Altas ,选个文件夹保存 Font Altas。
想要折腾就先不保存,上面还有很多的东西可以进行调试:
Source Font File:就是放字体源文件的地儿 |
Sampling Point Size /Font Size: This determines the accuracy of the SDF (Signed Distance Field) sampling in reproducing the font. The default setting of Auto Size will attempt to populate the atlas with all characters from the font. When set to Custom, higher values result in better reproduction. Generally a point size of 50 to 70 is a good range. Be cautious, however, because too large of a sampling size will prevent some characters from being in the atlas. (这个参数决定了SDF(Signed Distance Field)在生成字符的采样精确度。默认的设置,即 “Auto Size” 会尝试着将你的字体文件包含的所有字符都填充进生成的字体图文件(Font Altas)中 ,。如果你选择Custom Size选项,这个时候需要你手动设置,值约大,字体图形转换的精度越高,通常区间50 ~70就行了。需要注意的时值太高会导致某些字符不会出现在在字体图文件中) |
Padding:This dictates the size of effects (outlines, glow, bevels, etc.) from Font Materials. Generally, it’s good for the padding size to be at a 1:10 ratio to the sampling size. A sampling size of 60, for example, should have a padding size of 6. This, however, is not a hard and fast rule. Breaking this ratio can produce interesting effects that might better suit your aesthetic vision for your projects. (字符间的间的间距,该参数会影响字体材质的效果,如轮廓、光晕、斜面等。通常,取padding size/sampling point size 为1:10。但是取别的比例会生成一些很有趣的效果。) |
Packing Method: The method by which the atlas is populated. Fast is good for quickly previewing fonts, while Optimum is best reserved for the final atlas.(选择Fast则生成很快,选择Optimum 则生成的效果最好) |
Atlas Resolution: The size of the atlas Texture. This is determined by the Sampling Point Size and Padding. You should cap Atlas Resolution at 2048x2048 for projects targeting mobile devices.(生成的最终贴图的大小,该参数决定字体图的分辨率。参数由 Sampling Point Size与Padding参数决定。针对移动平台的项目,Atlas分辨率应限制在2048x2048。) |
Character Set: Determines the range of characters to use within the font. The default is ASCII. ( 选择字符集 ,默认 ASCII ,其他的一些选项说明如下
|
Render Mode: Determines how text will be presented. While displaying text at rasterized bitmaps is still supported, use SDF modes unless you’re rendering a small font on a 1:1 ratio (i.e., 10pt font rendered 10px on the screen). (确定文本的显示方式。虽然仍支持在光栅化位图上显示文本,但除非以1:1的比例渲染小字体,即在屏幕上渲染10px的10pt字体,否则请使用SDF模式。) |
Get Kerning Pairs: TextMesh Pro can optionally use the kerning information embedded in the font, if available. (可以选择使用 kerning information ) |
3. Once all settings are to your liking, select Generate Font Asset to import your new font.
Once your Font Asset has been created, you can access individual settings within the Inspector.(在你设置完毕后,点击Generate Font Asset 生成你的字体,生成好字体文件后,你可以在面板中设置独立的属性)
2. Dynamic and static Font Assets 动 / 静态字体资源
Sometimes we need to populate a Font Atlas with specific characters. One practical reason is creating a font from a subset of characters. This is particularly useful for languages with massive character sets (over 50,000 for Chinese). Most games use about 1,000 characters at most, and games with full Chinese and Japanese language support are some of the few that approach this range. Dynamic SDFs are an alternative way of populating a font atlas with only the characters we need by typing them into the input field. Font fallbacks will be used for all remaining characters as needed.(有时我们需要用特定地字符填充字体图集。如从字符子集创建字体。这对于具有大量字符集的语言(中文字符集超过50000)特别有用。大多数游戏最多使用1000个字符图形,而且要到1000个字符也是少数完全支持中文和日文的那种游戏。动态SDF只生成会用得到的字符集文件,动态asset会生成一个0Mb的asset资源,然后根据输入实时生成字符集合,优点是优秀的空间使用,但是会带来一定的性能负载。剩下的字符如果你想使用我们还有 Font fallbacks 功能)
If desired, the font atlases generated by these dynamically populated Font Assets can be exported, modified to contain external characters (i.e., remapping ‘A’ to a symbol not found in any font atlas), then reimported into Unity.(如果有需要, 动态生成的字体文件可以导出,然后往里面假如外部字符(也就是说可将一个特殊形状的“A”导入其中),然后重新导入Unity。)
步骤如下:
1. Navigate to your desired font within the project hierarchy. Then right-click Create > TextMeshPro > Font Asset. This will create a Font Asset with an empty atlas.(在你的字体文件图标上,依次点击Create > TextMeshPro > Font Asset ,这样你会在同目录下得到一个空的字体图文件)
2. Click on the newly created Font Asset. In the Inspector, navigate to Generation Settings and make sure Atlas Population Mode is set to Dynamic. (点击这个空内容的字体图文件,然后在对应的设置面板中让 Atlas Population Mode 的设置为 Dynamic)
3. Navigate to the TextMeshPro Object, choose this new Font Asset, and input the desired characters as needed.(然后你就可以到对应的 TextMeshPro 组件中使用生成的字体图啦)
It’s good to pack Font Assets dynamically when you need to populate an atlas at runtime (such as for any input fields). However, this requires the source font to be referenced and included within the project build. Static Font Assets are good for containing characters you know will be used throughout the project (menu items, dialog subtitles/text boxes, etc.). As Static Font Assets include all the characters required for the project, they do not need to reference the original font source file.(当您需要在运行时填充字体图的时候,使用动态打包字体资产是很好的。但是,这需要在项目中引用并包含源字体。静态字体资源适合于事先已知在整个项目中将要使用的字符(菜单项、对话框字幕/文本框等)。由于静态字体资源包括项目所需的所有字符,因此它们不需要引用原始字体源文件。)
In short, use static Font Assets for your “knowns” and dynamic Font Assets for your “unknowns.”
3. TMP设置
The TMP Settings Asset found in the TextMesh Pro > Resources folder is used to assign and manage default fonts, Sprites, and fallbacks. While we can apply local settings to individual fonts, the settings in this asset will affect every TextMeshPro Asset in the Scene .
( TextMesh Pro>Resources-> TMP Setting 用于 TextMeshPro插件的默认设置)
4. Font Weights
Font weights describe the various appearances your font can take, i.e., bold, italic.(Font weights 用于设置可采用的各种外观,即粗体、斜体等。)
These variations can either be loaded from a new Font Asset or “faked” via the following settings, some of which are default values (你可以导入新的字体实现效果,也可以方便地直接用Font weights 的设置来实现)
5. Font fallbacks
Occasionally we want to reference characters that our font doesn’t contain. Instead of replacing our primary Font Asset, we can instead rely on a fallback. Fallbacks are additional Font Assets that will be referenced when a character does not exist in our primary font.(有时需要用到字体图中不包含的字符。无需替换条字体图文件(font asset、SDF),而是使用fallback ,fallback 的存在就是为了当你的主字体图文件中不包含某个字符时,使用其他的字体资源文件)
Font fallbacks can be set globally within the TMP Settings Asset or locally per Font Asset.(可以设置一个 global 的 fallback ,也能给每个字体图单独设置 fallback)文章来源:https://www.toymoban.com/news/detail-417616.html
6. Multi-Atlas Textures
When dynamically populating a Font Atlas, there may come a point when the amount of characters exceed the size of the atlas. When this happens, characters that don’t fit will automatically be placed onto a new atlas and assigned as a fallback to the previous atlas. This is the underlying principle of Multi-Atlas Textures — the ability to populate new atlases as needed during run time. While their memory footprint is larger, they can be valuable for localization use and provide flexibility for modifying atlases at runtime.(字符过多,会生成俩文件,后面的自动作为前一个的fallback ,Multi-Atlas Textures的基本原理就是这个。这种机制占用内存大,但是灵活。)文章来源地址https://www.toymoban.com/news/detail-417616.html
到了这里,关于TextMesh Pro 1 : 官网文章翻译、基本使用视频教程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!