|
UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
|
A custom UI element that provides a visual preview of a GameObject prefab along with its detailed information. This element combines an ObjectField for prefab selection with an automatically generated preview image and metadata display. More...
Public Member Functions | |
| PrefabPreviewElement () | |
| Initializes a new instance of the PrefabPreviewElement, setting up the UI structure and styling. Creates and configures all child elements including the ObjectField, preview image, and detail labels. | |
| void | SetValueWithoutNotify (Object newValue) |
| Sets the value of the element without triggering change notifications or events. Updates the internal GameObject reference, preview image, and ObjectField display. | |
Static Public Attributes | |
| static readonly string | ussContainerClassName = "prefab-preview-container" |
| The CSS class name applied to the main container of the prefab preview element. | |
| static readonly string | ussDetailsClassName = "prefab-preview-details" |
| The CSS class name applied to the details text column containing prefab metadata. | |
| static readonly string | ussElementClassName = "prefab-preview-element" |
| The CSS class name applied to the preview image element. | |
| static readonly string | ussStylesheetPath = "prefab_preview_element" |
| The path to the USS stylesheet resource that styles this element. | |
Properties | |
| Object | value [get, set] |
| Gets or sets the current GameObject value of the element. Setting this property triggers change events and updates the preview display. | |
Private Member Functions | |
| void | OnObjectFieldValueChanged (ChangeEvent< Object > evt) |
| Handles value changes from the ObjectField and updates the element's value accordingly. This method is called when the user selects a different GameObject in the ObjectField. | |
| void | SetPreview (Object newValue) |
| Generates and sets the preview image and details for the specified GameObject. This method handles the asynchronous nature of Unity's AssetPreview system with a scheduled execution. | |
Private Attributes | |
| VisualElement | m_DetailsWrapper |
| Container element that wraps the preview image and details text column. | |
| ObjectField | m_ObjectField |
| The ObjectField that allows users to select and assign GameObject prefabs. | |
| Label | m_PrefabName |
| Label that displays the name of the selected prefab. | |
| Label | m_PrefabTags |
| Label that displays the tags associated with the selected prefab. | |
| Label | m_PrefabType |
| Label that displays the type information of the selected prefab. | |
| Label | m_PrefabUniqueId |
| Label that displays the unique instance ID of the selected prefab. | |
| Texture2D | m_Preview |
| The cached preview texture generated for the current prefab. | |
| Image | m_PreviewElement |
| The Image element that displays the visual preview of the selected prefab. | |
| GameObject | m_Value |
| The currently selected GameObject prefab value. | |
A custom UI element that provides a visual preview of a GameObject prefab along with its detailed information. This element combines an ObjectField for prefab selection with an automatically generated preview image and metadata display.
This element implements INotifyValueChanged to support Unity's data binding system and inherits from BindableElement. The preview image is generated asynchronously using Unity's AssetPreview system, with a delay to ensure proper loading. The element displays prefab name, unique instance ID, and tags alongside the visual preview. Requires Unity Editor as it uses AssetPreview and ObjectField functionality.
| GWG.UsoUIElements.CustomElements.PrefabPreviewElement.PrefabPreviewElement | ( | ) |
Initializes a new instance of the PrefabPreviewElement, setting up the UI structure and styling. Creates and configures all child elements including the ObjectField, preview image, and detail labels.
The constructor loads the associated stylesheet, configures the ObjectField for GameObject selection, creates the preview image and detail labels, and sets up the initial layout structure. The details wrapper is initially hidden and will be shown when a valid prefab preview is available.
|
private |
Handles value changes from the ObjectField and updates the element's value accordingly. This method is called when the user selects a different GameObject in the ObjectField.
| evt | The change event containing the old and new values from the ObjectField. |
This callback ensures that changes in the ObjectField are properly propagated to the element's value property, which will trigger the preview update and notification events.
|
private |
Generates and sets the preview image and details for the specified GameObject. This method handles the asynchronous nature of Unity's AssetPreview system with a scheduled execution.
| newValue | The GameObject to generate a preview for, or null to clear the preview. |
The method uses Unity's AssetPreview.GetAssetPreview to generate a visual representation of the prefab. Due to the asynchronous nature of preview generation, the method schedules an execution with a 2-frame delay to ensure the preview texture is available. When successful, it populates the preview image and all detail labels, then makes the details wrapper visible. If the preview generation fails, the details remain hidden.
| void GWG.UsoUIElements.CustomElements.PrefabPreviewElement.SetValueWithoutNotify | ( | Object | newValue | ) |
Sets the value of the element without triggering change notifications or events. Updates the internal GameObject reference, preview image, and ObjectField display.
| newValue | The new GameObject value to set, or null to clear the selection. |
| ArgumentException | Thrown when the newValue is not null and not a GameObject. |
This method is used internally to update the element's state without triggering change events, which is important for avoiding infinite loops during value synchronization. The method validates that the provided value is either null or a GameObject before proceeding.
|
private |
Container element that wraps the preview image and details text column.
This element uses horizontal flex direction to arrange the preview and details side by side. It's initially hidden and becomes visible when a valid prefab is selected and preview is generated.
|
private |
The ObjectField that allows users to select and assign GameObject prefabs.
This field is configured to only accept GameObject types and triggers preview updates when its value changes.
|
private |
Label that displays the name of the selected prefab.
Shows the prefab's name with HTML formatting for better visual presentation.
|
private |
Label that displays the tags associated with the selected prefab.
Shows the Unity tags assigned to the prefab with HTML formatting for better presentation.
|
private |
Label that displays the type information of the selected prefab.
Currently defined but not actively populated with type information in the current implementation.
|
private |
Label that displays the unique instance ID of the selected prefab.
Shows the Unity-generated unique identifier for the prefab instance with HTML formatting.
|
private |
The cached preview texture generated for the current prefab.
This texture is generated asynchronously by Unity's AssetPreview system and cached to avoid repeated generation.
|
private |
The Image element that displays the visual preview of the selected prefab.
This image is populated asynchronously using Unity's AssetPreview system and shows a rendered view of the prefab.
|
private |
The currently selected GameObject prefab value.
This represents the main value of the element and is synchronized with the ObjectField selection.
|
static |
The CSS class name applied to the main container of the prefab preview element.
Used for styling the overall container that holds all child elements of the prefab preview.
|
static |
The CSS class name applied to the details text column containing prefab metadata.
Used for styling the container that holds the prefab name, ID, type, and tags labels.
|
static |
The CSS class name applied to the preview image element.
Used for styling the image that displays the visual preview of the selected prefab.
|
static |
The path to the USS stylesheet resource that styles this element.
This stylesheet should be placed in a Resources folder and contains the visual styling for the prefab preview element.
|
getset |
Gets or sets the current GameObject value of the element. Setting this property triggers change events and updates the preview display.
The currently selected GameObject prefab, or null if no prefab is selected.
The setter implements the INotifyValueChanged pattern by creating and sending a ChangeEvent when the value actually changes. It uses SetValueWithoutNotify internally to update the display and then sends the appropriate change notification to any listeners.