54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
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 Button actionBtn;
|
|
|
|
public bool showing => GetComponent<CanvasGroup>().blocksRaycasts;
|
|
|
|
void Start()
|
|
{
|
|
m_instance = this;
|
|
actionBtn.onClick.AddListener(OnAction);
|
|
SetActive(false);
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
void OnAction(){
|
|
if(showing){
|
|
SetActive(false);
|
|
}
|
|
}
|
|
|
|
public async void ShowDialog(string title, string message){
|
|
titleTxt.text = title;
|
|
messageTxt.text = message;
|
|
|
|
|
|
SetActive(true);
|
|
Canvas.ForceUpdateCanvases();
|
|
GetComponentInChildren<VerticalLayoutGroup>().enabled=false;
|
|
GetComponentInChildren<VerticalLayoutGroup>().enabled=true;
|
|
|
|
|
|
|
|
// messageTxt.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void SetActive(bool value){
|
|
GetComponent<CanvasGroup>().blocksRaycasts= value;
|
|
GetComponent<CanvasGroup>().interactable= value;
|
|
GetComponent<CanvasGroup>().alpha= (value) ? 1: 0;
|
|
}
|
|
}
|