Native Dialogs

The API is build based on iOS ISN_UIAlertController and Android  AN_AlertDialog. The API can also be used inside Unity Editor. When using inside Unity Editor default EditorUtility will be used. 

The approach is pretty simple. 

  • Create UM_NativeDialogBuilder object and set up all required fields,
  • Generate new UM_iUIDialog object, that will represent a native dialog
  • Use UM_iUIDialog to Show / Hide the dialog when you need it

The API allows you to build most basic types of native dialogs. If you need to make more complex dialog, you can always use iOS & Android plugin API directly. Let's go through the code samples of the most popular dialog cases:

Message

A simple message to notify the user.

using SA.CrossPlatform.UI;
...

string title = "Congrats";
string message = "Your account has been verified";
var builder = new UM_NativeDialogBuilder(title, message);
builder.SetPositiveButton("Okay", () => {
    Debug.Log("Okay button pressed");
});

var dialog = builder.Build();
dialog.Show();

Dialog

Ask a user about something.

using SA.CrossPlatform.UI;
...

string title = "Save";
string message = "Do you want to save your progress?";
var builder = new UM_NativeDialogBuilder(title, message);
builder.SetPositiveButton("Yes", () => {
    Debug.Log("Yes button pressed");
});

builder.SetNegativeButton("No", () => {
    Debug.Log("No button pressed");
});

var dialog = builder.Build();
dialog.Show();

Destructive Dialog

This kind of dialog is recommended to use to indicate that action might change or delete data.

using SA.CrossPlatform.UI;
...

string title = "Confirmation ";
string message = "Do you want to delte this item?";
var builder = new UM_NativeDialogBuilder(title, message);
builder.SetPositiveButton("Cancel", () => {
    Debug.Log("Yes button pressed");
});

builder.SetDestructiveButton("Delete", () => {
    Debug.Log("Delete button pressed");
});

var dialog = builder.Build();
dialog.Show();

Complex Dialog

The dialog with 3 options for a user to choose from.

using SA.CrossPlatform.UI;
...

string title = "Save";
string message = "Do you want to save your progress>";
var builder = new UM_NativeDialogBuilder(title, message);
builder.SetPositiveButton("Yes", () => {
    Debug.Log("Yes button pressed");
});

builder.SetNegativeButton("No", () => {
    Debug.Log("Yes button pressed");
});

builder.SetNeutralButton("Later", () => {
    Debug.Log("Later button pressed");
});

var dialog = builder.Build();
dialog.Show();

Utility 

The plugin also provided simplified API version, using the  UM_DialogsUtility class. Just to allow you to execute most common simple action with just a few lines of code.

using SA.CrossPlatform.UI;
...

string title = "Save";
string message = "Do you want to save your progress>";
UM_DialogsUtility.ShowMessage(title, message );

Appearance 

Please see the screenshots below to get a basic understanding of how those popups would look on the device and while you're in the Editor testing phase.

iOS:

Android:

Unity Editor: