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

98 lines
3.0 KiB
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace UnityTest.ZXL
{
//强提示
public class StrongTipsUI : UI
{
public TextMeshProUGUI titleText;
public TextMeshProUGUI contentText;
public Button btnLeft;
public Button btnRight;
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);
}
public void SetContent(string title, string content)
{
titleText.text = title;
contentText.text = content;
}
public void SetContent(string title, string content, Action callback, int btnCount, bool isCenter = true)
{
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);
}
btnLeft.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "确定";
btnRight.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "取消";
if (isCenter)
contentText.alignment = TextAlignmentOptions.Center;
else
contentText.alignment = TextAlignmentOptions.Left;
}
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;
if (isCenter)
contentText.alignment = TextAlignmentOptions.Center;
else
contentText.alignment = TextAlignmentOptions.Left;
}
}
}