WX-Game1/Assets/Scripts/TMPTextFont.cs

30 lines
914 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class TMPTextFont : MonoBehaviour
{
public TMP_FontAsset fontAsset;
public TMP_Text text;
void Start()
{
WeChatWASM.WX.InitSDK((ret) =>
{
// fallbackFont作为旧版本微信或者无法获得系统字体文件时的备选CDN URL
// 「注意」需要替换成游戏真实的字体URL
var fallbackFont = Application.streamingAssetsPath + "/Fonts/AlibabaPuHuiTi-2-55-Regular.ttf";
WeChatWASM.WX.GetWXFont(
fallbackFont,
(font) =>
{
fontAsset = TMP_FontAsset.CreateFontAsset(font);
text.font=fontAsset;
}
);
}
);
}
}