Page 1 of 1

[HOWTO] How To: Confirm Response Menu Buttons

Posted: Thu Jun 27, 2024 3:54 pm
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