Skip to main content

Text Binders

Binders for TextMeshPro text components.


TextBinder

The main binder for TMP_Text.text. Accepts string and, through INumberBinder, numeric types.

PropertyDescription
TargetThe TMP_Text component
ConverterIConverter<string?, string?> (optional)
CultureInfoModeNumber formatting mode (Invariant, Current, Custom)

Data types: string, int, float, long, double (numbers go through ToCultureString).

Modes: OneWay, OneTime, OneWayToSource.

[ViewModel]
public partial class ScoreViewModel
{
[OneWayBind] private int _score; // TextBinder shows "1500"
[OneWayBind] private string _label; // TextBinder shows the text as is
}

TextSwitcherBinder

bool → one of two strings.

PropertyDescription
True ValueText for true
False ValueText for false

Modes: OneWay, OneTime.


TextFontBinder / TextFontSwitcherBinder

Binds the TMP_FontAsset:

BinderData typeDescription
TextFontBinderTMP_FontAssetSets the font
TextFontSwitcherBinderboolTMP_FontAssetPicks a font by condition

TextFontSizeBinder / TextFontSizeSwitcherBinder

Binds the font size:

BinderData typeDescription
TextFontSizeBinderfloatSets fontSize
TextFontSizeSwitcherBinderboolfloatPicks a size by condition

TextAlignmentBinder / TextAlignmentSwitcherBinder

Binds the text alignment:

BinderData typeDescription
TextAlignmentBinderTextAlignmentOptionsSets the alignment
TextAlignmentSwitcherBinderboolTextAlignmentOptionsPicks by condition

Other TMP_Text properties

BinderData typeProperty
TextFontStyleBinderFontStylesfontStyle
TextAutoSizeBinderboolenableAutoSizing
TextRichTextBinderboolrichText
TextCharacterSpacingBinderfloatcharacterSpacing
TextLineSpacingBinderfloatlineSpacing
TextMarginBinderVector4margin (left, top, right, bottom)
TextMaxVisibleCharactersBinderintmaxVisibleCharacters; 0 hides the text without clearing it

The numeric binders (FontSize, CharacterSpacing, LineSpacing, Margin) write finite values only: NaN is logged and skipped.


Example: showing stats

[ViewModel]
public partial class StatsViewModel
{
[OneWayBind] private int _health; // TextBinder → "100"
[OneWayBind] private bool _isAlive; // TextSwitcherBinder → "Alive" / "Dead"
}

See also