Dialog Box

The dialog box is a graphical control element in the from of a small window that communicates information to the user and prompts them for a response.

The following script shows how you can use the dialog box.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace DevionGames.UIWidgets
{
    public class DialogBoxTrigger : MonoBehaviour
    {
        /// <summary>
        /// Title to display
        /// </summary>
        public string title;
        /// <summary>
        /// Text to display
        /// </summary>
        [TextArea]
        public string text;
        /// <summary>
        /// Icon to show, can be null
        /// </summary>
        public Sprite icon;
        /// <summary>
        /// Button options like Yes, No, Cancel
        /// </summary>
        public string[] options;

        private DialogBox m_DialogBox;

        private void Start()
        {
            //Find the dialog box widget
            this.m_DialogBox = WidgetUtility.Find<DialogBox>("DialogBox");
        }

        public void Show()
        {
            //Show dialog box without callback
            m_DialogBox.Show(title, text, icon, null, options);
        }

        public void ShowWithCallback()
        {
            //Show dialog with callback "OnDialogResult"
            m_DialogBox.Show(title, text, icon, OnDialogResult, options);
        }

        /// <summary>
        /// Dialog box callback. 
        /// </summary>
        /// <param name="index"></param>
        private void OnDialogResult(int index)
        {
            //Just showing the callback result in a dialog box again.
            m_DialogBox.Show("Result", "Callback Result: " + options[index], icon, null, "OK");
        }
    }
}