培训考核三期,新版培训,网页版培训登录器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

81 lines
2.1 KiB

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 = ConvertToEn(tips);
sureAction = sure;
cancelAction = cancel;
transform.SetAsLastSibling();
gameObject.SetActive(true);
}
public static TipPanelManager GetInstance
{
get
{
if (instance == null)
{
var obj = Resources.Load<GameObject>("TipPanel");
var tips = Instantiate(obj, GameObject.Find("Canvas").transform);
tips.name = "TipPanel";
instance = tips.GetComponent<TipPanelManager>();
}
return instance;
}
}
/// <summary>
/// 英文字符转为中文字符
/// </summary>
/// <param name="text">转换的中文字符串</param>
/// <returns></returns>
public static string ConvertToEn(string text)
{
const string ch = "。;,?!、“”‘’()—";//中文字符
const string en = @".;,?!\""""''()-";//英文字符
char[] c = text.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
int n = ch.IndexOf(c[i]);
if (n != -1) c[i] = en[n];
}
return new string(c);
}
}