Elements
Image
An image display element for showing Texture2D images. Supports loading from resources, direct texture assignment, and async loading.
Constructor
new Image(texture2D); // Direct texture
new Image("path/to/texture"); // Load from Resources
new Image(asyncTextureTask); // Async loadingExamples
Unity Resource Loading
Load images from Unity's Resources system:
// Load from Resources folder
new Image("Icons/download-icon")
.ClassName("action-icon");
// Conditional icon based on ViewModel state
new Image()
.BindVisible(ViewModel.ShowIcon)
.ClassName("status-icon");Dynamic Image Selection
Switch images based on ViewModel properties:
// Different images based on state
new Image().BindVisible(ViewModel.PlayerAvatar.Select(avatar => avatar != null));
// Note: Image source binding would require custom implementation
// Icon that changes based on status
new Group(
new Image("Icons/online").BindVisible(ViewModel.IsOnline),
new Image("Icons/offline").BindVisible(ViewModel.IsOnline.Select(online => !online))
);UI Icons and Assets
Common Unity UI image patterns:
// Button with icon
new Button(
new Image("Icons/save"),
new Label("Save")
);
// Status indicator
new HorizontalGroup(
new Image("Icons/health").ClassName("health-icon"),
new ProgressBar(ViewModel.Health)
);
// Conditional visibility based on permissions
new Image("Icons/admin")
.BindVisible(ViewModel.IsAdmin);Properties
| Prop | Type | Default |
|---|---|---|
image | Texture2D | - |
disabled? | bool | false |
visible? | bool | true |
name? | string | "" |
pickingMode? | PickingMode | PickingMode.Position |
Methods
| Prop | Type | Default |
|---|---|---|
LoadImageAsync? | (Task<Texture2D>) => void | - |
Disabled? | (bool = true) => Image | - |
GetDisabled? | () => bool | - |
BindDisabled? | (Observable<bool>) => Image | - |
Visible? | (bool) => Image | - |
GetVisible? | () => bool | - |
BindVisible? | (Observable<bool>) => Image | - |
ClassName? | (string, bool = true) => Image | - |
BindClassName? | (string, Observable<bool>) => Image | - |
StyleSheet? | (StyleSheet) => Image or (string) => Image | - |
Image extends BaseElement.