[HOWTO] How To: Confirm Response Menu Buttons

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22189
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Confirm Response Menu Buttons

Post by Tony Li »

If you want to show a confirmation panel before accepting a response button click, make a subclass of StandardUIResponseButton and override the OnClick() method. The example script below overrides OnClick() to show a confirmation panel with confirm and cancel buttons. The cancel button hides the panel. The confirm button runs the base OnClick() method.

ResponseButtonWithConfirmation.cs

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;

public class ResponseButtonWithConfirmation : StandardUIResponseButton
{
    public GameObject confirmationPanel; //<-- Assign these in inspector.
    public Button confirmButton;
    public Button cancelButton;

    public override void OnClick()
    {
        confirmationPanel.SetActive(true);
        confirmButton.onClick.RemoveAllListeners();
        cancelButton.onClick.RemoveAllListeners();
        confirmButton.onClick.AddListener(() => { confirmationPanel.SetActive(false); base.OnClick(); });
        cancelButton.onClick.AddListener(() => confirmationPanel.SetActive(false));
    }
}
Here's an example scene that uses it:

DS_ConfirmResponseExample_2024-06-27.unitypackage
Post Reply