Class Dialog
A reusable dialog component that displays content in a modal window, often used for important information or actions that require user attention.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Dialog : BaseDialog, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement, IDismissInvocator
Remarks
The Dialog component provides a way to present content in a focused modal window, temporarily interrupting the user's workflow. It's commonly used for important notifications, gathering user input, or requiring user decisions.
Dialogs can contain various types of content including text, form elements, or custom components. They appear as modal windows overlaying the main content and typically include a title, content area, and optional action buttons.
Note: For situations requiring specific user decisions or acknowledgments, consider using the AlertDialog variant which provides pre-configured semantic variants and action buttons.
A Dialog's visibility is typically controlled by a Modal component, which handles the overlay and focus management.
Examples
Basic Dialog Example
var dialog = new Dialog
{
title = "Welcome",
description = "Welcome to our application! We hope you enjoy using it.",
size = Size.M,
dismissable = true
};
// Add the dialog to a modal
var modal = new Modal();
modal.Add(dialog);
// Add the modal to your UI hierarchy
rootElement.Add(modal);
UXML Dialog Definition
<UXML xmlns="UnityEngine.UIElements">
<Modal>
<ui:Dialog
title="Settings"
description="Configure your application settings below."
size="M"
dismissable="true">
<!-- Add custom content here -->
</ui:Dialog>
</Modal>
</UXML>
Dialog with Custom Content
var dialog = new Dialog();
dialog.title = "User Profile";
// Add custom content
var customContent = new VisualElement();
customContent.Add(new TextField("Name:"));
customContent.Add(new TextField("Email:"));
dialog.Add(customContent);
// Add action buttons
var saveButton = new Button(() => Debug.Log("Save clicked")) ;
var cancelButton = new Button(() => Debug.Log("Cancel clicked")) ;
dialog.actionContainer.Add(cancelButton);
dialog.actionContainer.Add(saveButton);
Constructors
Dialog()
Default constructor.
Declaration
public Dialog()
Fields
closeButtonUssClassName
The Dialog close button styling class.
Declaration
public const string closeButtonUssClassName = "appui-dialog__closebutton"
Field Value
| Type | Description |
|---|---|
| string |
dismissableUssClassName
The Dialog dismissable mode styling class.
Declaration
public const string dismissableUssClassName = "appui-dialog--dismissable"
Field Value
| Type | Description |
|---|---|
| string |
Properties
closeButton
The close button.
Declaration
public Button closeButton { get; }
Property Value
| Type | Description |
|---|---|
| Button |
Remarks
The button is only visible if dismissable is True.
dismissable
Set the Dialog dismissable by itself using a closeButton.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool dismissable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
ShouldHideHeading()
Check if the heading should be hidden. Override this method to change the default behavior. By default, the heading is hidden if the title is null or empty.
Declaration
protected override bool ShouldHideHeading()
Returns
| Type | Description |
|---|---|
| bool | True if the heading should be hidden, false otherwise. |
Overrides
Events
dismissRequested
Event fired when the Dialog is dismissed.
Declaration
public event Action<DismissType> dismissRequested
Event Type
| Type | Description |
|---|---|
| Action<DismissType> |