Version: 2021.3
Mesh Filter 组件
Using meshes with C# scripts

Text Mesh component (legacy)

The Text Mesh component generates 3D geometry that displays text strings.

Note: This is a legacy component that has limited functionality. For information on more recent, full-featured ways of displaying text, see Creating user interfaces (UI).

You can create a new Text Mesh from Component > Mesh > Text Mesh.

属性

属性: 功能:
Text 要渲染的文本
Offset Z 文本在绘制时应从 transform.position.z 偏移多远
Character Size 每个字符的大小(此设置会缩放整个文本。)
Line Spacing 文本的行间距。
Anchor 文本的哪个点共享变换位置。
Alignment 如何对齐文本行(选项包括 Left、Right、Center)。
Tab Size 为制表符“\t”字符插入的空格数。这是“空格键”字符偏移的倍数。
Font Size 字体的大小。此设置可覆盖动态字体的大小。
Font Style 字体的渲染样式。字体需要标记为动态。
Rich Text 选择此项后将在渲染文本时启用标签处理。
Font 渲染文本时使用的 TrueType 字体
Color 渲染文本时使用的全局颜色。

详细信息

Text Meshes can be used for rendering road signs, graffiti etc. The Text Mesh places text in the 3D scene. To make generic 2D text for GUIs, use a GUI Text component instead.

请按照以下步骤使用自定义字体创建文本网格:

  1. Import a font by dragging a TrueType Font - a .ttf file - from the Explorer (Windows) or Finder (OS X) into the Project View.
  2. Select the imported font in the Project View.
  3. Choose GameObject > Create Other > 3D Text. You have now created a text mesh with your custom TrueType Font. You can scale the text and move it around using the Scene View’s Transform controls.

注意:如果要更改文本网格的字体,需要设置该组件的字体属性,并将字体材质的纹理设置为正确的字体纹理。为此,可使用字体资源的折叠三角形来定位此纹理。如果忘记设置纹理,网格中的文本将显示为块状且未对齐。

最佳实践

  • You can download free TrueType Fonts from 1001freefonts.com (download the Windows fonts since they contain TrueType Fonts).
  • If you are scripting the Text property, you can add line breaks by inserting the escape character “\n” in your strings.
  • You can use simple markup to style text meshes. See the Styled Text page for more details.
  • Fonts in Unity render the font glyphs to a texture map before any further rendering. If the font size is set too small, these font textures will appear blocky. Since TextMesh assets are rendered using quads, it’s possible that if the size of the TextMesh and font texture differ, the TextMesh might display incorrectly.
Mesh Filter 组件
Using meshes with C# scripts
Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961