Files
JJBB/Assets/Project/Script/GUI/Base/FontChangeText.cs
2024-08-23 15:49:34 +08:00

83 lines
2.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Runtime.InteropServices;
using System;
using GCGame.Table;
using GCGame;
public class FontChangeText : Text
{
private const int LOCALE_SYSTEM_DEFAULT = 0x0800;
private const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
private const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);
/// <summary>
/// 将字符转换成简体中文
/// </summary>
/// <param name="source">输入要转换的字符串</param>
/// <returns>转换完成后的字符串</returns>
public static string ToSimplified(string source)
{
String target = new String(' ', source.Length);
int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, source, source.Length, target, source.Length);
return target;
}
/// <summary>
/// 讲字符转换为繁体中文
/// </summary>
/// <param name="source">输入要转换的字符串</param>
/// <returns>转换完成后的字符串</returns>
public static string ToTraditional(string source)
{
String target = new String(' ', source.Length);
int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, source, source.Length, target, source.Length);
return target;
}
//public void Start()
//{
// text = text;
//}
public bool useDicTable = false;
public int curDicID = -1;
public override string text
{
get
{
return base.text;
}
set
{
if (useDicTable)
{
int id = 0;
if (int.TryParse(value, out id))
{
curDicID = id;
value = Utils.GetDicByID(id);
}
}
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(base.text)) base.text = "";
}
else if (base.text != value)
{
base.text = value;
#if DYNAMIC_FONT
if (mFont != null) mFont.Request(value);
#endif
}
}
}
}