-
Notifications
You must be signed in to change notification settings - Fork 39
DisplayKit ElementReference
davidsebesta edited this page Jun 6, 2026
·
6 revisions
Complete API reference for DisplayKit elements.
Root container for all UI elements.
| Property | Type | Description |
|---|---|---|
Id |
int? |
Unique canvas identifier (auto-generated) |
SortOrder |
int? |
UI layering priority (higher = on top) |
DefaultVisibility |
CanvasVisibility |
Initial visibility for new observers (Visible/Hidden) |
Observers |
Dictionary<int, ObserverStatus> |
Players tracking with their status |
IdToElement |
Dictionary<int, IDisplayElement> |
Element lookup by ID |
IsGloballySpawned |
bool |
Whether canvas spawns for all players (global canvas) |
IdGenerator |
RecyclableIdGenerator |
ID generator for child elements |
| Method | Description |
|---|---|
Spawn() |
Send canvas to ALL current players AND late joiners (becomes global) |
Spawn(int connectionId) |
Send to specific player ONLY (per-player canvas) |
Spawn(ReferenceHub hub) |
Send to specific player by hub |
| Method | Description |
|---|---|
Show() |
Show canvas to all observers |
Hide() |
Hide canvas from all observers |
Show(int connectionId) |
Show to specific player |
Hide(int connectionId) |
Hide from specific player |
Show(ReferenceHub hub) |
Show to specific player by hub |
Hide(ReferenceHub hub) |
Hide from specific player by hub |
SetVisibility(bool visible) |
Set visibility for all observers |
SetVisibility(int connectionId, bool visible) |
Set visibility for specific player |
| Method | Description |
|---|---|
Destroy() |
Destroy canvas from all players and clean up |
| Event | Description |
|---|---|
OnPlayerCanvasConstructed |
Fired when a player successfully constructs this canvas |
// Create global canvas
DisplayCanvas canvas = DisplayCanvas.Create();
canvas.DefaultVisibility = CanvasVisibility.Visible;
canvas.SortOrder = 100;
canvas.Spawn(); // Becomes global - all players see same content
// Create per-player canvas
DisplayCanvas playerCanvas = DisplayCanvas.Create();
playerCanvas.DefaultVisibility = CanvasVisibility.Visible;
playerCanvas.Spawn(connectionId); // Only this player sees it
// Show/hide global canvas
canvas.Show();
canvas.Hide();
// Show/hide for specific player
canvas.Show(connectionId);
canvas.Hide(connectionId);
// Subscribe to event
canvas.OnPlayerCanvasConstructed += (connection) =>
{
Debug.Log($"Canvas constructed for {connection.connectionId}");
};
// Clean up
canvas.Destroy();Generic container element for organizing UI layout. Inherits all styling properties from Element<T>.
| Method | Returns | Description |
|---|---|---|
AddElement() |
DisplayElement |
Add a child container element |
AddText(string text = "") |
DisplayText |
Add a child text element |
Remove() |
void |
Remove element from hierarchy |
DisplayElement has access to all style containers (see Style Properties):
-
Background- Background color -
Flex- Flexbox layout -
Align- Alignment properties -
Size- Width, height, constraints -
Spacing- Padding and margin -
Border- Border styling -
Position- Absolute/relative positioning -
Transform- Translation, rotation, scale -
Display- Visibility, opacity, display mode
// Create container
DisplayElement panel = canvas.AddElement();
// Layout
panel.Flex.Direction = FlexDirection.Column;
panel.Size.Width = 300f;
// Styling
panel.Background.Color = Color.gray;
panel.Border.Color = Color.white;
panel.Border.Width = 2f;
panel.Border.Radius = 10f;
panel.Spacing.Padding = 15f;
// Add children
DisplayText title = panel.AddText("Title");
DisplayElement content = panel.AddElement();
// Remove
panel.Remove();Text display element. Inherits all styling properties from Element<Label> plus text-specific properties.
| Property | Type | Description |
|---|---|---|
Content |
string |
The text content to display |
| Method | Returns | Description |
|---|---|---|
AddElement() |
DisplayElement |
Add a child container element |
AddText(string text = "") |
DisplayText |
Add a child text element |
Remove() |
void |
Remove element from hierarchy |
DisplayText has access to all style containers plus:
-
Text- Font, size, color, alignment, shadow, etc.
See Style Properties - Text for complete text styling reference.
// Create text
DisplayText label = canvas.AddText("Hello World");
// Update content
label.Content = "Updated Text";
// Style text
label.Text.Font = FontType.RobotoBold;
label.Text.FontSize = 24f;
label.Text.Color = Color.yellow;
label.Text.Align = TextAnchor.MiddleCenter;
// Add shadow
label.Text.TextShadow = new TextShadow
{
color = Color.black,
offset = new Vector2(2, 2),
blurRadius = 4f
};
// Style container (inherited)
label.Background.Color = Color.blue;
label.Spacing.Padding = 10f;
// Remove
label.Remove();All elements (DisplayCanvas, DisplayElement, DisplayText) share these base properties:
| Property | Type | Description |
|---|---|---|
Id |
int? |
Unique element ID within canvas |
Root |
DisplayCanvas |
Root canvas containing this element |
Parent |
IDisplayElement |
Parent element in hierarchy |
Children |
List<IDisplayElement> |
Child elements |
Base |
T |
Wrapped Unity VisualElement |
BaseElement |
VisualElement |
Base element exposed via interface |
IsLoaded |
bool |
Whether element has finished loading |
HasChanges |
bool |
Whether element has unsynchronized changes |
// Access hierarchy
DisplayElement parent = element.Parent;
DisplayCanvas root = element.Root;
// Add to parent (automatic when using AddElement/AddText)
DisplayElement child = parent.AddElement();
// Check loaded state
if (child.IsLoaded)
{
// Element is ready
}
// Check for pending changes
if (child.HasChanges)
{
// Changes will be synced this frame
}- Style Properties - Complete styling reference
- Examples - Practical usage examples
- Sending to Players - Canvas scope and spawning
- Making Plugins
- Features
- Guides