[HOWTO] How To: Confirm Response Menu Buttons
Posted: Thu Jun 27, 2024 3:54 pm
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
Here's an example scene that uses it:
DS_ConfirmResponseExample_2024-06-27.unitypackage
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));
}
}
DS_ConfirmResponseExample_2024-06-27.unitypackage