91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class TipPanel : MonoBehaviour
|
||
{
|
||
public Button btnClose;
|
||
public Button btnContine;
|
||
|
||
public Text txtUpload;
|
||
public Text txtInfo;
|
||
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
btnClose.onClick.AddListener(() =>
|
||
{
|
||
this.gameObject.SetActive(false);
|
||
});
|
||
btnContine.onClick.AddListener(() =>
|
||
{
|
||
this.gameObject.SetActive(false);
|
||
});
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
|
||
public void UpdatePanel(IsSuccessMsg msg)
|
||
{
|
||
if (msg.success)
|
||
{
|
||
txtUpload.text = "上传成功";
|
||
txtInfo.text = msg.msg;
|
||
}
|
||
else
|
||
{
|
||
txtUpload.text = "上传失败";
|
||
Debug.Log(msg.msg);
|
||
int j = msg.msg.IndexOf("关");
|
||
int i = int.Parse(msg.msg.Substring(1, j-1));
|
||
string str = ConvertToChineseNumber(i);
|
||
txtInfo.text = "第" + str + "关还没有创建,请先创建第" + str + "关关卡。";
|
||
}
|
||
}
|
||
|
||
string ConvertToChineseNumber(int number)
|
||
{
|
||
string[] chineseDigits = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
|
||
string[] chineseUnits = { "", "十", "百", "千", "万" };
|
||
|
||
string result = "";
|
||
int unitIndex = 0;
|
||
|
||
if (number == 0) return chineseDigits[0]; // 如果是0,直接返回“零”
|
||
|
||
while (number > 0)
|
||
{
|
||
int digit = number % 10; // 取最后一位数字
|
||
if (digit > 0 || unitIndex == 0) // 避免中文大写中的“零百”,“零十”
|
||
{
|
||
result = chineseDigits[digit] + chineseUnits[unitIndex] + result;
|
||
}
|
||
else if (digit == 0 && result.Length > 0 && result[0] != '零') // 处理零
|
||
{
|
||
result = "零" + result;
|
||
}
|
||
number /= 10; // 去掉最后一位数字
|
||
unitIndex++;
|
||
}
|
||
|
||
// 特殊处理十的情况,比如"十二"而不是"一十二"
|
||
if (result.StartsWith("一十"))
|
||
{
|
||
result = result.Substring(1);
|
||
}
|
||
|
||
// 移除结果末尾的多余“零”
|
||
if (result.EndsWith("零"))
|
||
{
|
||
result = result.TrimEnd('零');
|
||
}
|
||
|
||
return result;
|
||
}
|
||
}
|