using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using System; public class TipPanelManager : MonoBehaviour { public TextMeshProUGUI showText; public Button sureBtn; public Button cancelBtn; private static TipPanelManager instance; private Action sureAction; private Action cancelAction; private TipPanelManager() { } void Start() { sureBtn.onClick.AddListener(sureBtn_Click); cancelBtn.onClick.AddListener(cancelBtn_Click); } private void cancelBtn_Click() { if (cancelAction != null) cancelAction.Invoke(); gameObject.SetActive(false); } private void sureBtn_Click() { if (sureAction != null) sureAction.Invoke(); gameObject.SetActive(false); } public void Show(string tips, Action sure = null, Action cancel = null) { showText.text = tips; sureAction = sure; cancelAction = cancel; transform.SetAsLastSibling(); gameObject.SetActive(true); } public static TipPanelManager GetInstance { get { if (instance == null) { var obj = Resources.Load("TipPanel"); var tips = Instantiate(obj, GameObject.Find("Canvas").transform); tips.name = "TipPanel"; instance = tips.GetComponent(); } return instance; } } }