Tanoda
YesNoPopupManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using GILES;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class YesNoPopupManager : pb_MonoBehaviourSingleton<YesNoPopupManager>
9{
10 [SerializeField] private Text titleUi;
11 [SerializeField] private Text textUi;
12 [SerializeField] private Button yesButton;
13 [SerializeField] private Button noButton;
14 [SerializeField] private GameObject popupWindow;
15 [SerializeField] private CanvasGroup cg;
16 private Action onYes;
17 private Action onNo;
18
19 public void ShowPopup(string title, string text)
20 {
21 titleUi.text = Macro.T(title);
22 textUi.text = Macro.T(text);
23 yesButton.GetComponentInChildren<Text>().text = Macro.T("YES");
24 noButton.GetComponentInChildren<Text>().text = Macro.T("NO");
25
26#if UNITY_WEBGL
27 cg.alpha = 1f;
28 cg.blocksRaycasts = true;
29 cg.interactable = true;
30 noButton.onClick.AddListener(invokerNo);
31#else
32 popupWindow.SetActive(true);
33#endif
34 }
35
36 public void ShowPopup(string title, string text, string yes, string no)
37 {
38 titleUi.text = Macro.T(title);
39 textUi.text = Macro.T(text);
40 yesButton.GetComponentInChildren<Text>().text = Macro.T(yes);
41 noButton.GetComponentInChildren<Text>().text = Macro.T(no);
42
43#if UNITY_WEBGL
44 cg.alpha = 1f;
45 cg.blocksRaycasts = true;
46 cg.interactable = true;
47 noButton.onClick.AddListener(invokerNo);
48#else
49 popupWindow.SetActive(true);
50#endif
51
52 }
53
54 public void HidePopup()
55 {
56#if UNITY_WEBGL
57 cg.alpha = 0f;
58 cg.blocksRaycasts = false;
59 cg.interactable = false;
60#else
61 popupWindow.SetActive(false);
62#endif
63 }
64 public void InvokeOnYes(Action action)
65 {
66 onYes = action;
67 yesButton.onClick.AddListener(invokerYes);
68 }
69
70 private void invokerYes()
71 {
72 onYes?.Invoke();
73 yesButton.onClick.RemoveListener(invokerYes);
74 onYes = null;
75 onNo = null;
76 HidePopup();
77 }
78
79 public void InvokeOnNo(Action action)
80 {
81 onNo = action;
82 noButton.onClick.AddListener(invokerNo);
83 }
84
85 private void invokerNo()
86 {
87 onNo?.Invoke();
88 noButton.onClick.RemoveListener(invokerNo);
89 onYes = null;
90 onNo = null;
91 HidePopup();
92 }
93}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
Definition: Macro.cs:12
static string T(string key)
Definition: Macro.cs:19
void InvokeOnNo(Action action)
void ShowPopup(string title, string text, string yes, string no)
void InvokeOnYes(Action action)
void ShowPopup(string title, string text)