Version: 2021.3
言語: 日本語
背景画像の設定
テスト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.
背景画像の設定
テストUI