Docsv3.31.0
Back to API Reference
Class

SpriteModifier

sealed

Embeds Sprite assets inline with text as glyphs of the text mesh. The set of named sprites available to <sprite=name> tags is supplied by an ISpriteProvider.

Remarks

Tag syntax: <sprite=name[,colorArg][,aspect][,size][,offset][,advance][,lineHeightAbove][,lineHeightBelow][,pivot][,rotation]>. The optional second positional argument controls the rendered color of this occurrence: omitted — use the keyed override when present, otherwise the provider entry's own InlineSprite.Color. i — inherit the host UniText component's color. Equivalent to CSS currentColor. #RGB/#RRGGBB/#RRGGBBAA or a named color (red, blue, …) — explicit per-occurrence override. Examples: <sprite=heart>, <sprite=heart,i>, <sprite=heart,#FF0000>. aspect (true/false) and the shared presentation overrides (size, bearing offset, advance, line space above/below — em units; pivot — normalized; rotation — degrees) resolve through the override hierarchy, weakest → strongest: provider entry → keyed override → default parameters → tag attribute. Every sprite is a glyph of the process-wide SpriteFont: it takes its place in the layer stack, renders in world-space text, and receives the layer effects (shadow, glow, stroke, …) whose colour-glyph policy applies to it. It draws from its own texture at native resolution — one sub-mesh per distinct texture, so the sprites of one atlas share a draw call — and a tightly packed sprite draws by its own outline mesh. The sprite name resolves through Provider; a matching keyed override changes only its presentation. Built-in providers: InlineSpriteProvider (default — inline list on the modifier), AssetSpriteProvider (shared UniTextSprites asset). For dynamic catalogs — input-prompt icon services, localisation, item icons — implement ISpriteProvider directly and raise its Changed event when the resolution result changes.
public ISpriteProvider Provider{ get; set }

Source of named inline sprites.

protected INamedCatalog<InlineSprite> Catalog{ get }
protected override bool HasRenderable(InlineSprite entry)
protected override UniTextDirty MemberStage(StateMember member)

Cheapest rebuild stage that carries a change of member — of a catalog entry or of a keyed override — to the screen. Size, pivot and rotation are values this class only forwards to OnMediaShaped, so they default to UniTextDirty.Positions: any value a subclass turns into shaping-slot or positioned-glyph output is stale under UniTextDirty.Mesh, which reuses the positioned glyphs. An override classifies the members its own entry and override types declare, and lowers a forwarded member to UniTextDirty.Mesh only when it consumes that member no earlier than mesh generation.

protected override void OnEnable()
protected override void OnDisable()
protected override void OnDestroy()
protected override void BeforeApply()
protected override void OnShapingStarted()
protected override void OnMediaShaped(int cluster, in ResolvedMedia media, ref ShapedGlyph glyph, float fontSize)

Resolves the occurrence's glyph and box: the sprite keeps its aspect inside the box, held to the box's pivot, or stretches to fill it; the offsets land in the shaping slot, the scales in the placement. The glyph is requested with the silhouette field any effect asked for on this cluster — the only atlas work a sprite ever needs.

protected override void OnExtraTokens(int cluster, InlineSpriteOverride mediaOverride, ref ParameterReader reader)

See Also