Dialog
Note
See Windows Animations for open and closed animations.
Options
- Buttons Templates - ReadOnlyCollection<Button>- Templates for the buttons. 
- Content Root - RectTransform- Root gameobject for the content. 
- Title Text - Text(obsolete)- GameObject to display title. Replaced with the DialogInfo. 
- Content Text - Text(obsolete)- GameObject to display text. Replaced with the DialogInfo. 
- Icon - Image(obsolete)- GameObject to display icon. Replaced with the DialogInfo. 
- Dialog Info - DialogInfoBase- Component to display the dialog info. 
- AutoFocus - bool- Set focus to the last Selectable object in the Dialog. 
- Close Button - Button- Button to close dialog. 
- Buttons Container - RectTransform- Buttons container. If container not specified will be used parent of the button template. 
- Hide on Modal Click - bool- Close dialog on click on the background if the - modaloption enabled.
Events
- OnAnimationStart - UnityEvent<bool>- The event is raised before the animation starts. - Arguments: true if opening animation; false if closing animation. 
Show() Method Parameters
title and message also can be specified with SetInfo()- title - stringDialog title.Can be changed with- SetInfo()method.
- message - stringDialog message.Can be changed with- SetInfo()method.
- buttons - ButtonsPoolDialog buttons.Can be changed with- SetButtons()method.- DialogButtonfields:- Label - string- Button label. 
- Action - Func<DialogBase, int, bool>- Function to run on button click. Receive dialog instance and button index, return - trueto close dialog; otherwise- false.
- Template Index - int- Index of the button template. 
 
- focusButton - stringButton with focus by default.Can be changed with- SetButtons()or- FocusButton().
- position - Vector3?Dialog position.Can be changed with- SetPosition().
- icon - SpriteDialog icon.Can be changed with- SetInfo()method.
- modal - boolModal dialog.Can be changed with- SetModal().
- modalSprite - SpriteBackground image for the modal dialog.Can be changed with- SetModal().
- modalColor - Color?Background color for the modal dialog.Can be changed with- SetModal().
- canvas - CanvasCanvas to display dialog. Required if dialog template is prefab.Can be changed with- SetCanvas().
- content - RectTransformDialog content. Can be used instead of the message and icon.Can be changed with- SetContent().
- onClose - ActionAction to run when dialog closed.Can be changed with- OnClosefield.
- onCancel - Func<int, bool>Function to run when dialog canceled. Receive dialog instance and -1as button index, return- trueif dialog should be closed.Obsolete, use- Func<DialogBase, int, bool> OnDialogCancelfield instead.
ShowAsync() Method Parameters
title and message also can be specified with SetInfo()-1 in case of Cancel() method.- title - stringDialog title.Can be changed with- SetInfo()method.
- message - stringDialog message.Can be changed with- SetInfo()method.
- buttons - ButtonsPoolDialog buttons.Can be changed with- SetButtons()method.- DialogButtonfields:- Label - string- Button label. 
- Action - Func<DialogBase, int, bool>- Function to run on button click. Receive dialog instance and button index, return - trueto close dialog; otherwise- false.
- Template Index - int- Index of the button template. 
 
- focusButton - stringButton with focus by default.Can be changed with- SetButtons()or- FocusButton().
- position - Vector3?Dialog position.Can be changed with- SetPosition().
- icon - SpriteDialog icon.Can be changed with- SetInfo()method.
- modal - boolModal dialog.Can be changed with- SetModal().
- modalSprite - SpriteBackground image for the modal dialog.Can be changed with- SetModal().
- modalColor - Color?Background color for the modal dialog.Can be changed with- SetModal().
- canvas - CanvasCanvas to display dialog. Required if dialog template is prefab.Can be changed with- SetCanvas().
- content - RectTransformDialog content. Can be used instead of the message and icon.Can be changed with- SetContent().
- closeOnButtonClick - bool- Close dialog on button click. 
Minimal code
// create dialog instance
var dialog = dialogTemplate.Clone();
// show dialog
dialog.Show();
// specify root canvas if dialog cloned from prefab
dialog.Show(canvas: canvas);
Advanced
// create dialog instance
var dialog = dialogPrefab.Clone();
// show dialog with following parameters
dialog.Show(
   title: "Modal Dialog",
   message: "Simple Modal Dialog.",
   buttons: new DialogButton[]
   {
      new DialogButton(
        "Close", // label
        DialogBase.DefaultClose, // Func<DialogBase, int, bool>, receive dialog instance and button index, return true to close dialog, otherwise false
        0 // button index in ButtonsTemplates
      ),
   },
   focusButton: "Close",
   modal: true,
   modalColor: new Color(0, 0, 0, 0.8f)
);
Async
// create dialog instance
var dialog = dialogPrefab.Clone();
// show dialog with following parameters
var button_index = await dialog.ShowAsync(
   title: "Modal Dialog",
   message: "Simple Modal Dialog.",
   buttons: new DialogButton[]
   {
      "Do Some Action",
      "Do Other Action",
      "Close",
   },
   focusButton: "Close",
   modal: true,
   modalColor: new Color(0, 0, 0, 0.8f)
);
if (button_index == 0)
{
   Debug.Log("Do Some Action");
}
else if (button_index == 1)
{
   Debug.Log("Do Other Action");
}
Adding new behaviour
- Create helper component - using UnityEngine; using UnityEngine.UI; public class DialogInputHelper : MonoBehaviour { [SerializeField] public InputField Username; [SerializeField] public InputField Password; // Reset values public void Refresh() { Username.text = ""; Password.text = ""; } public bool Validate() { var valid_username = Username.text.Trim().Length > 0; var valid_password = Password.text.Length > 0; if (!valid_username) { Username.Select(); } else if (!valid_password) { Password.Select(); } return valid_username && valid_password; } } 
- Show dialog. - public void ShowDialogSignIn() { var dialog = dialogSignIn.Clone(); var helper = dialog.GetComponent<DialogInputHelper>(); helper.Refresh(); dialog.Show( title: "Sign into your Account", buttons: new DialogButton[] { // on click call SignInNotify new DialogButton("Sign in", SignInNotify), // on click close dialog new DialogButton("Cancel"), }, focusButton: "Sign in", modal: true, modalColor: new Color(0, 0, 0, 0.8f) ); } bool SignInNotify(DialogBase dialog, int index) { var helper = dialog.GetComponent<DialogInputHelper>(); if (!helper.Validate()) { return false; } //show notification var message = "Sign in.\nUsername: " + helper.Username.text + "\nPassword: <hidden>"; notifySample.Clone().Show(message, customHideDelay: 3f); return true; } 
Custom Dialogs
You can create derived class with own methods and fields.
public class MyDialog : DialogCustom<MyDialog>
{
   // ...
}