[ゲーム開発][Unity]TextMeshProで中国語と日本語のフォントを切り替えます

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class LoadTTF : MonoBehaviour
{
    public bool useJap;
    public TextMeshProUGUI UI_Text;
    public TMP_FontAsset chineseAsset;
    public TMP_FontAsset japAsset;
    // Start is called before the first frame update
    void Start()
    {
        if (useJap)
        {
            UI_Text.font = japAsset;
            UI_Text.text = "ござじずぜぞだぢづでどぱぴぷぺぽばびぶべぼらりるれろやゆよわァィゥヴェォカヵキクケコサシスセソタチツッテト";
        }
        else
        {
            UI_Text.font = chineseAsset;
            UI_Text.text = "这是中文啊";
        }

    }
}

TMP_FontAsset

 下の図は、公式 github デモで生成された 7 つの言語フォントを示しています。

これは Unity によってシリアル化されたアセット ファイルであり、このファイルはエディターにロードすることも、アセットバンドルにパッケージ化してロードすることもできます。

おすすめ

転載: blog.csdn.net/liuyongjie1992/article/details/134166240