Dialog

Minimal code

// create dialog from template
var dialog = dialogTemplate.Clone();
// show dialog
dialog.Show();
// specify root canvas if dialog cloned from prefab
dialog.Show(canvas: canvas);

Advanced

// create dialog from template
var dialog = dialogPrefab.Clone();
// show dialog with following parametres
dialog.Show(
   title: "Modal Dialog",
   message: "Simple Modal Dialog.",
   buttons: new DialogActions(){
      // Button name and Func<bool>, return true to close dialog, otherwise false
      {"Close", Dialog.Close},
   },
   focusButton: "Close",
   modal: true,
   modalColor: new Color(0, 0, 0, 0.8f)
);

Adding new behaviour

  1. 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;
       }
    }
    
  2. 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 DialogActions(){
             {"Sign in", () => SignInNotify(helper)},
             {"Cancel", Dialog.Close},
          },
          focusButton: "Sign in",
          modal: true,
          modalColor: new Color(0, 0, 0, 0.8f)
       );
    }
    
    bool SignInNotify(DialogInputHelper helper)
    {
       //if username or password empty than don't close dialog
       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;
    }