109 lines
3.0 KiB
C#
Executable File
109 lines
3.0 KiB
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
[RequireComponent(typeof(CanvasGroup))]
|
|
public class MessageDialog : MonoBehaviour
|
|
{
|
|
|
|
private static MessageDialog m_instance;
|
|
public static MessageDialog instance=>m_instance;
|
|
public TMPro.TMP_Text titleTxt;
|
|
public TMPro.TMP_Text messageTxt;
|
|
// public GameObject closeButton;
|
|
public Button okayBtn;
|
|
public Button yesBtn;
|
|
public Button noBtn;
|
|
|
|
|
|
|
|
public bool showing => GetComponent<CanvasGroup>().blocksRaycasts;
|
|
|
|
void Start()
|
|
{
|
|
m_instance = this;
|
|
okayBtn.onClick.AddListener(OnOkay);
|
|
yesBtn.onClick.AddListener(OnClickedYes);
|
|
noBtn.onClick.AddListener(OnClickedNo);
|
|
SetActive(false);
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
void OnOkay(){
|
|
if(showing){
|
|
SetActive(false);
|
|
}
|
|
AudioManager.instnace.UIClick();
|
|
|
|
}
|
|
|
|
public void ShowMessage(string title, string message){
|
|
Debug.Log(message + ", Already Showing : " + isActive);
|
|
if(isActive){
|
|
StartCoroutine(RescheduleMessage(title,message));
|
|
return;
|
|
}
|
|
titleTxt.text = title;
|
|
messageTxt.text = message;
|
|
|
|
yesBtn.gameObject.SetActive(false);
|
|
noBtn.gameObject.SetActive(false);
|
|
okayBtn.gameObject.SetActive(true);
|
|
SetActive(true);
|
|
Refresh();
|
|
AudioManager.instnace.UIPopup();
|
|
|
|
// messageTxt.gameObject.SetActive(true);
|
|
}
|
|
|
|
IEnumerator RescheduleMessage(string title, string message){
|
|
yield return new WaitForSeconds(0.1f);
|
|
|
|
ShowMessage(title, message);
|
|
}
|
|
UnityAction onYes = ()=>{};
|
|
UnityAction onNo = ()=>{};
|
|
|
|
public void ShowQuestion(string title, string message, UnityAction OnYes, UnityAction OnNo, bool onlyYes = false){
|
|
titleTxt.text = title;
|
|
messageTxt.text = message;
|
|
onYes = OnYes;
|
|
onNo = OnNo;
|
|
|
|
yesBtn.gameObject.SetActive(true);
|
|
|
|
noBtn.gameObject.SetActive(!onlyYes);
|
|
okayBtn.gameObject.SetActive(false);
|
|
SetActive(true);
|
|
Refresh();
|
|
AudioManager.instnace.UIPopup();
|
|
}
|
|
void OnClickedYes(){
|
|
OnOkay();
|
|
if(onYes!=null){onYes();}
|
|
AudioManager.instnace.UIClick();
|
|
}
|
|
void OnClickedNo(){
|
|
OnOkay();
|
|
if(onNo!=null){onNo();}
|
|
AudioManager.instnace.UIClick();
|
|
}
|
|
public void SetActive(bool value){
|
|
GetComponent<CanvasGroup>().blocksRaycasts= value;
|
|
GetComponent<CanvasGroup>().interactable= value;
|
|
GetComponent<CanvasGroup>().alpha= (value) ? 1: 0;
|
|
isActive=value;
|
|
}
|
|
|
|
bool isActive;
|
|
|
|
void Refresh(){
|
|
Canvas.ForceUpdateCanvases();
|
|
GetComponentInChildren<VerticalLayoutGroup>().enabled=false;
|
|
GetComponentInChildren<VerticalLayoutGroup>().enabled=true;
|
|
}
|
|
}
|