Class TextModeView
World-space MonoBehaviour component for rendering a text mode cell grid. Manages a CellGrid and CellBufferRenderer to display a fixed grid of character cells with SDF font rendering. Grid columns, rows, and cell dimensions are auto-computed from FontSize, PixelsPerUnit, and the view dimensions (ViewWidth/ViewHeight).
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
[ExecuteAlways]
[DisallowMultipleComponent]
[AddComponentMenu("Scylla/TextMode/TextMode View")]
public class TextModeView : MonoBehaviour, ITextModeRenderSource, ITextModeGridProvider
Properties
CellBorder
Gets the frame of border cells around the grid. The world-space view has no border, so this is always None.
Declaration
public TextModeCellBorder CellBorder { get; }
Property Value
| Type | Description |
|---|---|
| TextModeCellBorder |
CellSize
Gets the computed cell size in world units.
Declaration
public Vector2 CellSize { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
CharSpacing
Gets or sets the character spacing multiplier. 1.0 = natural advance width. Values below 1.0 pack characters tighter. Changing this recomputes the grid layout.
Declaration
public float CharSpacing { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Columns
Gets the auto-computed number of columns in the grid.
Declaration
public int Columns { get; }
Property Value
| Type | Description |
|---|---|
| int |
CursorColor
Gets or sets the cursor color.
Declaration
public Color CursorColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
DefaultBackground
Gets or sets the default background color used for empty cells, and for cells the grid fills when it is cleared or resized.
Declaration
public Color32 DefaultBackground { get; set; }
Property Value
| Type | Description |
|---|---|
| Color32 |
Remarks
As with DefaultForeground, this affects future writes and clears only.
DefaultForeground
Gets or sets the default foreground color used for cells written without an explicit color, and for cells the grid fills when it is cleared or resized.
Declaration
public Color32 DefaultForeground { get; set; }
Property Value
| Type | Description |
|---|---|
| Color32 |
Remarks
Setting this changes what future writes and clears use. It does not recolor cells that already hold a color, because every cell stores its own. Use TextModeThemeRemapper to retint existing content.
DrawSelf
Gets or sets whether the view draws its grid itself. Defaults to true.
Declaration
public bool DrawSelf { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When false, the view skips its draw call, but it keeps uploading cells, running effects, blinking the cursor and handling selection. A component that shows the grid in another form, such as the CRT, turns it off and sets it back when it goes away. See ITextModeRenderSource.
Effects
Gets the effect player for this view, creating it the first time it is used.
Declaration
public TextModeEffectPlayer Effects { get; }
Property Value
| Type | Description |
|---|---|
| TextModeEffectPlayer |
Remarks
A view that never runs an effect never creates a player, so the cost of the effects
system on an unused view is one null check per frame. Once created, the player is
advanced in LateUpdate just before the grid is uploaded to the GPU, so effect
writes reach the screen in the same frame they are computed.
Returns null until the view is initialized, because effects need a grid to write into.
FollowColorTheme
Gets or sets whether this view adopts the active color theme when the theme changes.
Declaration
public bool FollowColorTheme { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Enabled by default, which is what makes a global theme switch repaint every view without the game redrawing anything. Turn it off for a view whose colors are owned by another system, so a theme change leaves them alone. The debug console is the case this exists for: it paints a transparent background so its own gradient shows through, and a theme would otherwise overwrite that with an opaque color.
Turning this off suppresses only later theme changes. Colors already applied stay as they are, so set it before the first theme is applied when the view must never be retinted at all.
FontAsset
Gets or sets the TMP font asset used for glyph rendering. Setting a new font at runtime triggers a full re-initialization.
Declaration
public TMP_FontAsset FontAsset { get; set; }
Property Value
| Type | Description |
|---|---|
| TMP_FontAsset |
FontSize
Gets or sets the font size in logical pixels. Cell height = fontSize / pixelsPerUnit. Changing this recomputes the grid layout.
Declaration
public float FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
GlyphCache
Gets the glyph atlas cache for stamping cells with glyph data.
Declaration
public GlyphAtlasCache GlyphCache { get; }
Property Value
| Type | Description |
|---|---|
| GlyphAtlasCache |
Grid
Gets the cell grid for reading and writing cell data.
Declaration
public CellGrid Grid { get; }
Property Value
| Type | Description |
|---|---|
| CellGrid |
IsInitialized
Gets whether the view is initialized and ready for rendering.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LineHeight
Gets or sets the line height multiplier. 1.0 = natural line height. Values above 1.0 add vertical spacing between rows. Changing this recomputes the grid layout.
Declaration
public float LineHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Remarks
Values below 1.0 pack the rows closer together without changing the size of the glyphs. The space a line does not use is given up first, so nothing is lost down to roughly 0.82; below that the glyphs reach into the rows above and below, which draw the overhanging parts rather than clipping them.
Assigning this takes ownership of the value. Until then the view uses the default line height from the TextMode module configuration and follows it when the configuration changes, in the same way it follows the configured SDF settings.
Material
Gets the renderer material for direct shader property access.
Declaration
public Material Material { get; }
Property Value
| Type | Description |
|---|---|
| Material |
PixelsPerUnit
Gets or sets the pixels-per-unit conversion factor. Higher values produce smaller cells. Changing this recomputes the grid layout.
Declaration
public float PixelsPerUnit { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
PointerMapper
Gets or sets the mapper that converts screen points to grid positions, or null to use the view's own area. Defaults to null. See PointerMapper.
Declaration
public ITextModePointerMapper PointerMapper { get; set; }
Property Value
| Type | Description |
|---|---|
| ITextModePointerMapper |
Rows
Gets the auto-computed number of rows in the grid.
Declaration
public int Rows { get; }
Property Value
| Type | Description |
|---|---|
| int |
SRGBCorrection
Gets or sets whether sRGB-to-linear correction is applied when unpacking cell colors. Enable for correct brightness in Linear color space. Default is true.
Declaration
public bool SRGBCorrection { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
SelectionColor
Gets or sets the background of selected cells.
Declaration
public Color SelectionColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Remarks
Selected cells are drawn in SelectionTextColor on this color, in place of their own colors. The built-in themes pick the pair so a selection reads as inverse text.
SelectionTextColor
Gets or sets the text color of selected cells. See SelectionColor.
Declaration
public Color SelectionTextColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
ViewHeight
Gets or sets the view height in world units. Changing this recomputes the number of rows.
Declaration
public float ViewHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ViewWidth
Gets or sets the view width in world units. Changing this recomputes the number of columns.
Declaration
public float ViewWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
ApplyTheme(in TextModeColorScheme)
Applies a color theme to this view, replacing the default foreground and background, the cursor color and the selection color with the theme's.
Declaration
public void ApplyTheme(in TextModeColorScheme scheme)
Parameters
| Type | Name | Description |
|---|---|---|
| TextModeColorScheme | scheme | The resolved theme colors to apply. |
Remarks
This changes what the view writes and clears with from now on. Text already on the grid keeps the colors it was written with, because every cell stores its own; pass the grid to TextModeThemeRemapper as well to retint it.
Reinitialize()
Forces a full re-initialization. Call if the font asset changes at runtime.
Declaration
public void Reinitialize()
ResetCursorBlink()
Replaces the active cell grid reference with an external grid. Used when a TerminalEmulator switches between primary and alternate screen buffers. The new grid must have the same dimensions as the current grid.
Declaration
public void ResetCursorBlink()
ScreenPointToCell(Vector2, Camera, out CellPosition)
Converts a screen point to a cell position in the grid. Performs a raycast from the screen point onto the grid's XY plane, then converts the world-space hit to local cell coordinates.
Note: The cell coordinate calculation assumes the grid transform has uniform scale and no rotation. Non-uniform scale or rotation may produce incorrect cell positions.
Declaration
public bool ScreenPointToCell(Vector2 screenPoint, Camera eventCamera, out CellPosition cellPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | screenPoint | Screen-space point (e.g. from |
| Camera | eventCamera | Camera used for the raycast. |
| CellPosition | cellPosition | The resulting cell position if the point is within the grid. |
Returns
| Type | Description |
|---|---|
| bool | True if the screen point maps to a valid cell in the grid. |
SetCell(int, int, uint, Color32, Color32, CellAttributes)
Sets a cell at the specified position with glyph atlas stamping.
Declaration
public void SetCell(int row, int col, uint codepoint, Color32 fg, Color32 bg, CellAttributes attributes = CellAttributes.None)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | Row index. |
| int | col | Column index. |
| uint | codepoint | Unicode codepoint. |
| Color32 | fg | Foreground color. |
| Color32 | bg | Background color. |
| CellAttributes | attributes | Cell attributes. |
SetGrid(CellGrid)
Declaration
public void SetGrid(CellGrid newGrid)
Parameters
| Type | Name | Description |
|---|---|---|
| CellGrid | newGrid |
SetViewSize(float, float)
Sets both view dimensions at once, triggering a single layout recomputation.
Declaration
public void SetViewSize(float width, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | View width in world units. |
| float | height | View height in world units. |
TryWriteCellProperties(MaterialPropertyBlock)
Writes everything a cell shader needs to shade this view's grid into a property block: the cell buffer, the grid size, the border and its color, the font atlas, the SDF, cursor and selection settings and the current blink phases.
Declaration
public bool TryWriteCellProperties(MaterialPropertyBlock block)
Parameters
| Type | Name | Description |
|---|---|---|
| MaterialPropertyBlock | block | The property block to write into. Existing values are overwritten. |
Returns
| Type | Description |
|---|---|
| bool | True if the view is initialized and the block holds a complete set of properties. |
Remarks
The cell size is not written, because it depends on the target. The caller sets
_CellSize itself.