跳至主要内容

UIToolkitTextSource Component

Component Screenshot

Overview

This component renders text internally using Unity's UI Toolkit and then renders the result to Unity UI (UGUI). This allows more complex text rendering such as Arabic, Urdu, Hebrew, Malayalam etc to now be rendered in the Canvas.

Properties

Component Screenshot

Property                            Type    Range    DefaultDescription
TextStringThe text that appears - can include Rich Text tags.
Font
    Generator ModeEnumStandardThe text generator mode to use.
    FontFontThe font to use.
    Font AssetFontThe font asset - if this is assigned then it overrides the Font property.
    Font SizeFloat14.0The font size.
Styling
    StyleEnumNormalNormal / Bold / Italic style.
    ColorColorWhiteThe text color.
    OutlineBooleanWhether or not TextMeshPro's outline effect is used.
    ShadowBooleanWhether or not TextMeshPro's shadow effect is used.
Layout
    Text AnchorEnumMiddleCenterThe text alignment.
    WrapEnumNoWrapThe text wrapping mode.
    OverflowEnumClipThe text overflow mode.
    Letter SpacingFloat0.0Add extra spacing between letters.
    Word SpacingFloat0.0Add extra spacing between words.
    Paragraph SpacingFloat0.0Add extra spacing between paragraphs/lines.
    Edge PaddingInt16The amount of padding in pixels to add to both sides of the texture. This helps with certain text rendering styles that will normally overflow the texture - such as Bold, Italics, Shadow and Outline.
Style SheetThe stylesheet to use during UIToolkit rendering. This must be assigned!
Raycast TargetBooleanTrueWhether or not this Graphic should support the raycaster (picking).
MaskableBooleanTrueWhether or not this Graphic should support the masking components.

Setup

COMPATIBILITY

This component uses UIToolkit runtime which is not available before Unity 2021.2

To use this component you first need to have support for UI Toolkit enabled:

  1. Make sure UI Toolkit package is enabled to your project (it's usually built-in)
  2. Go to the Edit > Project Preferences window and open the UIFX options, enabled UI Toolkit Support and press the Apply Changes button.

    screenshot
  3. Wait for the scripts to reload
  4. Close the Preferences window

Usage

Add this component to a GameObject in the Canvas hierarchy and assign the properties (Stylesheet, Font etc).