LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/StrongTipsUI.cs

98 lines
3.0 KiB
C#
Raw Normal View History

2023-09-14 15:36:17 +08:00
using System;
using TMPro;
2023-09-13 15:04:19 +08:00
using UnityEngine;
using UnityEngine.UI;
namespace UnityTest.ZXL
{
//强提示
2023-09-13 15:31:44 +08:00
public class StrongTipsUI : UI
2023-09-13 15:04:19 +08:00
{
public TextMeshProUGUI titleText;
public TextMeshProUGUI contentText;
public Button btnLeft;
public Button btnRight;
2023-09-14 15:36:17 +08:00
private Action _action;
public override void OnInit()
{
base.OnInit();
btnLeft.onClick.AddListener(ClickSure);
btnRight.onClick.AddListener(ClickCancel);
}
private void ClickSure()
{
UIManager.Instance().HideUI(uiType);
_action?.Invoke();
}
private void ClickCancel()
{
UIManager.Instance().HideUI(uiType);
}
2023-09-13 15:04:19 +08:00
public void SetContent(string title, string content)
{
titleText.text = title;
contentText.text = content;
}
2023-10-03 09:29:05 +08:00
public void SetContent(string title, string content, Action callback, int btnCount, bool isCenter = true)
2023-09-13 15:04:19 +08:00
{
titleText.text = title;
contentText.text = content;
2023-09-14 15:36:17 +08:00
_action = callback;
2023-09-13 15:04:19 +08:00
btnLeft.gameObject.SetActive(true);
btnRight.gameObject.SetActive(true);
if (btnCount == 0)
{
btnLeft.gameObject.SetActive(false);
btnRight.gameObject.SetActive(false);
}
else if (btnCount == 1)
{
btnRight.gameObject.SetActive(false);
}
btnLeft.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "确定";
btnRight.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "取消";
2023-10-03 09:29:05 +08:00
if (isCenter)
contentText.alignment = TextAlignmentOptions.Center;
else
contentText.alignment = TextAlignmentOptions.Left;
}
2023-10-03 09:29:05 +08:00
public void SetContent(string title, string content, Action callback, int btnCount, bool isCenter, string btn1Name = "", string btn2Name = "")
{
titleText.text = title;
contentText.text = content;
_action = callback;
btnLeft.gameObject.SetActive(true);
btnRight.gameObject.SetActive(true);
if (btnCount == 0)
{
btnLeft.gameObject.SetActive(false);
btnRight.gameObject.SetActive(false);
}
else if (btnCount == 1)
{
btnRight.gameObject.SetActive(false);
}
if (!string.IsNullOrEmpty(btn1Name))
btnLeft.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = btn1Name;
if (!string.IsNullOrEmpty(btn2Name))
btnRight.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = btn2Name;
2023-10-03 09:29:05 +08:00
if (isCenter)
contentText.alignment = TextAlignmentOptions.Center;
else
contentText.alignment = TextAlignmentOptions.Left;
2023-09-13 15:04:19 +08:00
}
}
}