Docsv2.12.12
Back to API Reference
Class

UniTextFont

Serialized ScriptableObject wrapper around a runtime font Core. Stores font bytes, faceInfo and editor-tweakable settings; instantiates a Core on first Runtime access. The Core does all glyph work and is the type consumed by shaping/atlas code paths.

Derived Types(2)

Types that inherit from UniTextFont.

Nested Types

public Core Runtime{ get }

Lazy-built runtime that owns the FT face, glyph tables and atlas pipeline. All glyph work flows through this. Subclasses override CreateRuntime to supply bytes from non-serialized sources.

protected bool HasRuntime{ get }

True if Runtime is already materialized. Avoids triggering lazy build.

public byte[] FontData{ get }

Raw font file bytes (TTF/OTF). Decompressed on first access; may be null before Runtime resolves.

public bool HasFontData{ get }

True when font bytes are available (either serialized or supplied by a subclass).

public int FontDataHash{ get }

Per-instance hash used as the high bits of every atlas/shaper key. Mixes the raw bytes hash with the asset instance id so duplicates and variants get independent atlas/shaper state.

public FaceInfo FaceInfo{ get; set }

Font face metrics (ascender, descender, line height, etc.).

public int UnitsPerEm{ get; set }

Font design units per em (typically 1000 or 2048). Fundamental scaling unit: scale = fontSize / unitsPerEm.

public float FontScale{ get; set }

Visual scale multiplier. Compensates for fonts that render visually smaller/larger than peers at the same size (e.g. Dongle).

public bool ParticipatesInNormalization{ get; set }

Whether font-size normalization may scale this font to match the primary font. Disable to keep a decorative font's intrinsic proportions.

public float ItalicStyle{ get; set }

Synthetic italic slant in degrees, applied as a horizontal skew when an italic tag is set. 0 falls back to DefaultItalicStyle.

public int SpacingOffset{ get; set }

Baseline spacing added to every glyph's advance during shaping, in font design units. Layered additively with style-level letter-spacing.

public int SpaceAdvance{ get; set }

Space (U+0020) advance for this font, in design units; replaces the width HarfBuzz reports. SpaceAdvanceUninitialized = use the font's own / HarfBuzz fallback.

public float FakeBoldWeight{ get; set }

Baseline synthetic bold in CSS weight steps from the font's own weight (1 ≈ Regular → Bold). Renders thicker via SDF dilate and compensates advance to keep layout stable. No effect on color emoji fonts.

public int AtlasPadding{ get }

Atlas gutter in pixels around each glyph tile, prevents bilinear bleeding.

public bool IsVariable{ get }

True if this font defines OpenType variable axes.

public bool IsColor{ get }

True for color (emoji/COLR) fonts — they bypass the SDF pipeline.

public string CachedName{ get }

Cached name string usable on worker threads (Unity's name getter is main-thread-only).

public Dictionary<long,Glyph> GlyphLookupTable{ get }

(varHash48, glyphIndex) → atlas-resident Glyph. Null until the font's lookup tables are built.

protected virtual Core CreateRuntime()

Subclass hook: produce the Core, or null if bytes unavailable.

protected void InvalidateRuntime()

Tears down the current runtime; next Runtime access rebuilds.

protected virtual Core BuildRuntime()

Subclass hook: instantiate a Core from bytes. Default uses serialized config.

public virtual int GetCachedInstanceId()

Cached Unity instance id, suitable for use as a dictionary key.

public virtual UniTextFontError LoadFontFace()

Loads the underlying FreeType face. Returns the resulting error code, or Success if already loaded.

public void ReadFontAssetDefinition()

Builds glyph and character lookup dictionaries and synthesizes invisible control characters (tab, line separators, BOM marks).

public uint GetGlyphIndexForUnicode()

Resolves a codepoint to a glyph index via HarfBuzz, with controlled fallbacks for NBSP/soft-hyphen.

public void RegisterCharacterEntries()

Adds (unicode, glyphIndex) pairs to the character table for entries discovered after the initial font load (e.g. variation selectors, emoji sequences).

public bool HasGlyphInAtlas()

True if the glyph is already rasterised in the atlas for this font's default variation hash.

public virtual void ClearDynamicData()

Drops the FT face, glyph caches and atlas entries owned by this font. Next access rebuilds on demand.

public void InvokeChanged()

Manually fires the Changed event. Use after editor edits that affect rendering but not atlas residency.

protected virtual void OnEnable()
protected virtual void OnDisable()
protected virtual void OnDestroy()
public static void ClearRuntimeData()

Disposes runtimes for all live Cores and invalidates shared caches.

public static int ComputeFontDataHash()

Cheap content hash of font bytes (FNV-1a variant, sampling step on large files). Stable across runs and matches the value stored in FontDataHash before instance-id mixing.

protected void ResetInstanceFontDataHash()
public static UniTextFont CreateFontAsset()

Builds a runtime UniTextFont from font file bytes. Compresses bytes in editor, stores raw at runtime; FT face is loaded once to populate FaceInfo and units-per-em.

protected byte[] fontData
protected int fontDataHash
public static const float DefaultItalicStyle

Synthetic-italic slant used when a font stores none (value 0), notably OS system-font fallbacks built at runtime. The italic modifier reads it as a horizontal shear factor.