Class CanvasCulling
Level-of-detail and viewport-culling helpers for content placed in a Canvas.
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public static class CanvasCulling
Remarks
Mirrors the registry's canvas-lod and canvas-culling modules. The canvas never
applies them on its own: a consumer reads zoom to pick a level for its
nodes and edges, and keeps only the content that overlaps the rect
TryGetVisibleContentRect(out Rect, float) returns.
Fields
boxZoomThreshold
The default zoom below which content draws at Box. Under about a third of full scale a node's title is no longer readable.
Declaration
public const float boxZoomThreshold = 0.3
Field Value
| Type | Description |
|---|---|
| float |
compactZoomThreshold
The default zoom below which content draws at Compact. Under half scale a node's port labels fall below a readable size.
Declaration
public const float compactZoomThreshold = 0.5
Field Value
| Type | Description |
|---|---|
| float |
defaultMargin
The default screen margin, in pixels, that culling keeps around the viewport, so content panned or zoomed into view is already there instead of appearing a frame late.
Declaration
public const float defaultMargin = 200
Field Value
| Type | Description |
|---|---|
| float |
Methods
IsVisible(CanvasEdge, Rect)
Whether an edge should be kept for a visible content box. An edge is kept by its own bounds, so an edge crossing the view between two off-screen nodes stays while its nodes do not. A selected or active edge is always kept.
Declaration
public static bool IsVisible(CanvasEdge edge, Rect view)
Parameters
| Type | Name | Description |
|---|---|---|
| CanvasEdge | edge | The edge. |
| Rect | view | The visible content box. |
Returns
| Type | Description |
|---|---|
| bool | Whether to keep the edge. |
IsVisible(CanvasNode, Rect, float)
Whether a node should be kept for a visible content box: it overlaps the box, or it is selected, which keeps it whatever its position.
Declaration
public static bool IsVisible(CanvasNode node, Rect view, float height = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| CanvasNode | node | The node. |
| Rect | view | The visible content box. |
| float | height | The node's content-space height; its laid-out height when 0 or less, or, before the first layout, the height of its header and port rows. |
Returns
| Type | Description |
|---|---|
| bool | Whether to keep the node. |
LevelOfDetailForZoom(float, float, float)
The level of detail to draw at for a zoom, where 1 is 100%.
Declaration
public static CanvasLevelOfDetail LevelOfDetailForZoom(float zoom, float compactThreshold = 0.5, float boxThreshold = 0.3)
Parameters
| Type | Name | Description |
|---|---|---|
| float | zoom | The canvas zoom. |
| float | compactThreshold | Below this zoom, content draws compact. |
| float | boxThreshold | Below this zoom, content draws as a box. Lower than |
Returns
| Type | Description |
|---|---|
| CanvasLevelOfDetail | The level of detail. |
TryViewportToContent(float, Vector2, Vector2, float, out Rect)
The content-space box a viewport shows, grown by margin screen pixels on
every side.
Declaration
public static bool TryViewportToContent(float zoom, Vector2 offset, Vector2 size, float margin, out Rect contentRect)
Parameters
| Type | Name | Description |
|---|---|---|
| float | zoom | The canvas zoom. |
| Vector2 | offset | Where the content origin sits on screen, in pixels from the viewport's top-left corner. |
| Vector2 | size | The viewport's on-screen size, in pixels. |
| float | margin | The screen margin to keep around the viewport. |
| Rect | contentRect | The visible content-space box. |
Returns
| Type | Description |
|---|---|
| bool | False while the viewport has no size or the zoom is not positive, when nothing can be said about what is visible. |