| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- [RequireComponent(typeof(CanvasGroup))]
- public class GenericDialog : MonoBehaviour {
- public Text title;
- public Text message;
- public Text accept, decline;
- public Button acceptButton, declineButton;
- private CanvasGroup cg;
- void Awake() {
- cg = GetComponent<CanvasGroup>();
- }
- public GenericDialog SetOnAccept(string text, UnityAction action) {
- accept.text = text;
- acceptButton.onClick.RemoveAllListeners();
- acceptButton.onClick.AddListener(action);
- return this;
- }
- public GenericDialog SetOnDecline(string text, UnityAction action) {
- decline.text = text;
- declineButton.onClick.RemoveAllListeners();
- declineButton.onClick.AddListener(action);
- return this;
- }
- public GenericDialog SetTitle(string title) {
- this.title.text = title;
- return this;
- }
- public GenericDialog SetMessage(string message) {
- this.message.text = message;
- return this;
- }
- public void Show() {
- this.transform.SetAsLastSibling();
- cg.blocksRaycasts = true;
- cg.alpha = 1f;
- cg.interactable = true;
- }
- public void Hide() {
- cg.interactable = false;
- cg.alpha = 0f;
- cg.blocksRaycasts = false;
- }
- private static GenericDialog instance;
- public static GenericDialog Instance() {
- if (!instance) {
- instance = FindObjectOfType(typeof(GenericDialog)) as GenericDialog;
- if (!instance) {
- Debug.Log("There need to be at least one active GenericDialog on the screen");
- }
- }
- return instance;
- }
- }
|