UniTextBase
UniTextBase partial class implementing auto-size and layout computation.
Remarks
ILayoutElement and ILayoutController so Unity's LayoutRebuilder drives the two phases; world-space has the render pipeline invoke EnsureLayoutFit directly. Two-phase design. The phases have independent caches because they key on different inputs and are driven by different UI rebuild points: EnsureLayoutComputed — the main pass. Computes the "preferred" state (cachedPreferredHeight and initial cachedEffectiveFontSize) at the unconstrained ideal font size. Cached by rect.width; independent of rect.height. Invoked from CalcLayoutInputVertical and returns what the parent layout group reads as "what this text wants". EnsureLayoutFit — the second pass. When auto-size is on and the actual rect.height is smaller than the preferred, shrinks cachedEffectiveFontSize to fit. Cached by rect.height. Deliberately does not update cachedPreferredHeight — "preferred" stays what the text wants, not what the rect gives it. Without this separation, shrinking preferred on one frame would make parents (e.g. ContentSizeFitter + VerticalLayoutGroup) assign an even smaller rect next frame, causing a feedback shrink loop.Nested Types
public UniTextDirtyFlags CurrentDirtyFlags{ get }Gets the current dirty flags indicating what needs rebuilding.
public TextProcessor TextProcessor{ get }Gets the text processor instance handling shaping and layout.
public UniTextMeshGenerator MeshGenerator{ get }Gets the mesh generator instance.
public UniTextFontProvider FontProvider{ get }Gets the font provider managing font assets and fallbacks.
public UniTextBuffers Buffers{ get }Gets the buffer container for text processing.
public ReadOnlyMemory<char> RawText{ get }Gets the runtime source text — the last value assigned via Text or any SetText overload, before any resolver substitution. Zero-alloc. Backing is either a string or a char buffer supplied to SetText.
public ReadOnlyMemory<char> ResolvedText{ get }Gets the substitute produced by the attached TextResolver on the last rebuild, or an empty memory when no resolver is attached or TryResolve returned. Zero-alloc. Test TextOverride for Resolver to know if this value is in use.
public ReadOnlyMemory<char> RenderedText{ get }Gets the text actually fed into the parsing / shaping / layout pipeline: the resolver's output if one is active, otherwise RawText. Zero-alloc. Still contains markup; for the markup-stripped form use CleanText.
public ReadOnlySpan<char> CleanText{ get }Gets RenderedText with parsed markup removed. Zero-alloc. The backing buffer is pooled and may be rewritten on the next parse — do not store the span; call new string(span) if you need a stable string.
public TextOverrideSource TextOverride{ get }Combination of flags describing which runtime source(s) are currently overriding the serialized Text. Flags may combine — for example, SetText | Resolver when a SetText buffer feeds an attached resolver that further substitutes the text.
public IUniTextResolver TextResolver{ get; set }Gets or sets a resolver that may override the source text before parsing without modifying the serialized text field. Useful for editor-time localization preview and runtime text-binding without dirtying scenes or prefabs. See IUniTextResolver for the contract.
public Vector2 ResultSize{ get }Gets the computed size of the rendered text.
public ReadOnlySpan<PositionedGlyph> ResultGlyphs{ get }Gets the positioned glyphs after processing.
public UniTextFont PrimaryFont{ get }Gets the primary font from the font collection.
public IReadOnlyList<Style> Styles{ get }Gets the list of registered modifiers.
public IReadOnlyList<StylePreset> StylePresets{ get }Gets the list of modifier configuration assets.
When (default), GlobalStylePreset is applied to this component as an extra preset registered after the local StylePresets list. Disable to opt this component out of project-wide rules — local Styles and local StylePresets still apply. Toggling the value invalidates the parser so the next pipeline pass picks up the new effective preset set.
public TextHighlighter Highlighter{ get; set }Gets or sets the text highlighter for visual feedback on interactions.
public UniTextFontStack FontStack{ get; set }Gets or sets the font collection.
public TextDirection BaseDirection{ get; set }Gets or sets the base text direction (LTR, RTL, or Auto-detect).
public HorizontalAlignment HorizontalAlignment{ get; set }Gets or sets the horizontal text alignment.
public VerticalAlignment VerticalAlignment{ get; set }Gets or sets the vertical text alignment.
public TextOverEdge OverEdge{ get; set }Gets or sets the top edge metric for text box trimming.
public TextUnderEdge UnderEdge{ get; set }Gets or sets the bottom edge metric for text box trimming.
public LeadingDistribution LeadingDistribution{ get; set }Gets or sets how extra leading from line-height is distributed.
public UniTextRenderMode RenderMode{ get; set }Gets or sets the text rendering mode (SDF for rounded, MSDF for sharp corner effects).
public Color color{ get; set }public TextHitResult LastHoverResult{ get }Gets the last hover hit test result.
public InteractiveRange CurrentHoverRange{ get }Gets the interactive range currently being hovered, if any.
public IEnumerable<Style> GetStylesOfType()Enumerates every style whose modifier is of type T, local first.
public IEnumerable<Style> GetStylesOfType()Enumerates every style whose modifier is assignable to modifierType, local first.
Unity callback invoked after Animator writes animated properties into this component's serialized fields. Subclasses delegate to their composed AnimationHandlerBase<T> to diff the animated state and aggregate the resulting UniTextDirtyFlags in a single SetDirty call.
Diffs animated fields against the cached baseline through the subclass's animation handler. Implementations should forward to their composed AnimationHandlerBase<T> instance.
public void SetText(ReadOnlyMemory<char> source)Sets the text to render without writing to the serialized text field. The change is visible at runtime and in edit mode without marking the scene or prefab as dirty — suitable for editor-time preview (localization) or transient runtime substitution.
public void AddRule(IParseRule rule)Adds a standalone parse rule (one that operates without a modifier, e.g. <noparse>). The rule must report IsStandalone as.
public bool RemoveRule(IParseRule rule)Removes a standalone rule previously added via AddRule.
public void CollectRangeEntries(int startCluster, int endCluster, PooledList<LineRangeEntry> output)Collects per-line geometric runs of positioned glyphs whose clusters fall inside [startCluster, endCluster). Output bounds are in mesh-local coordinates with X clamped to each line's visible content extent (trailing whitespace excluded via width). One LineRangeEntry is emitted per contiguous run within a line — multiple entries per line are possible if the matched clusters are non-contiguous in visual order.
Gets bounding rectangles for a cluster range. One Rect per contiguous run of glyphs within a line that falls inside [startCluster, endCluster). Trailing whitespace at line ends is excluded (CSS Text §4.1.3). Empty wrapped lines whose break codepoint lies inside the range receive a synthetic narrow rect for caret/selection rendering.
public TextHitResult HitTest(Vector2 localPosition, float maxDistance)Performs hit testing in local coordinates.
public TextHitResult HitTestScreen(Vector2 screenPosition, Camera eventCamera, float maxDistance)Performs hit testing from screen coordinates.
protected ReadOnlyMemory<char> sourceTextprotected TextDirection baseDirectionprotected TextOverEdge overEdgeprotected TextUnderEdge underEdgeprotected LeadingDistribution leadingDistributionprotected TextProcessor textProcessorprotected UniTextMeshGenerator meshGeneratorprotected UniTextBuffers buffersprotected List<UniTextRenderData> renderDatapublic CachedTransformData cachedTransformDataCached transform data captured before parallel processing.
public Action AnimatedRaised after Unity Animator applies animated property values to this component, once the base field diff has issued the corresponding SetDirty. Modifiers with their own animatable fields should subscribe and run an equivalent diff over their state, calling SetDirty with the flags that match their effect.
public Action RebuildingRaised before text is rebuilt.
public Action BeforeGenerateMeshRaised after glyph positioning but before mesh generation. Modifiers inject virtual PositionedGlyphs here.
public Action RectHeightChangedRaised when the RectTransform height changes.
public Action<UniTextDirtyFlags> DirtyFlagsChangedRaised when dirty flags change, indicating what needs rebuilding.
public static Action BeforeProcessRaised before any text processing in the current canvas update cycle.
public static Action MeshAppliedRaised after meshes are applied to renderers, before canvas rendering begins.
public static Action AfterProcessRaised after all text processing is complete, after MeshApplied.
public Action<TextHitResult> TextClickedRaised when any text is clicked, providing hit test details.
public Action<InteractiveRangeHit> RangeClickedRaised when an interactive range is clicked.
public Action<InteractiveRangeHit> RangeEnteredRaised when the pointer enters an interactive range (desktop only).
public Action<InteractiveRangeHit> RangeExitedRaised when the pointer exits an interactive range (desktop only).
public Action<TextHitResult> HoverChangedRaised when hover position changes, providing hit test details (for InputField).
