Version: 2021.3
言語: 日本語
Set background images
Test UI

Styling text

Basic text styling

Text properties are regular USS style properties. You can set text style properties on any element, regardless of whether it’s a text element (inheriting from TextElement C# type) or not. Unlike most USS style properties, text style properties propagate to child elements. For example:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    <ui:VisualElement style="-unity-font-style: bold-and-italic; font-size: 39px;">
        <ui:Label text="Label" />
    </ui:VisualElement>
</ui:UXML>

In the example above, the Label text will be bold, italic, and have a font size of 39px. The image below displays the available text style properties in the Inspector:

TextStyleFields
TextStyleFields

Style text directly in the Canvas

The following text styles are exposed as toggles in the Canvas on selected elements:

  1. Horizontal Text Align
  2. Vertical Text Align
  3. Text Wrap

These toggles appear in the header of the selected element, if the selected element is a text element (inherits from TextElement). For example, Label and Button:

CanvasTextToggles
CanvasTextToggles

Advanced text styling

You can install the TextMeshPro package, which Unity installs by default. The package features include:

  1. The use of rich text tags in Label text attributes.
  2. The use of the more advanced Font Asset in style properties, which allows setting text highlights and shadows.
Set background images
Test UI
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961