1. 注意点
- 系统字为一个库,并不是每一种字体都支持你需要的文本,因此需要自己寻找一个适合的文本
1. 在UGUI.Text中使用
// 获得系统字体名称列表
string[] systemFontNames = Font.GetOSInstalledFontNames();
// 获得某种字体
into index = 0;
string systemFontName = systemFontNames[index];
Font font = Font.CreateDynamicFontFromOSFont(systemFontName, 36);
GetComponent<Text>().font = font;
2. 在UGUI.TMP_Text中使用
必须是TMP 3.2以上版本
// 获得系统字体名称列表
string[] systemFontNames = Font.GetOSInstalledFontNames();
// 获得某种字体
into index = 0;
string systemFontName = systemFontNames[index];
// 创建字体文件
var fontAsset = TMP_FontAsset.CreateFontAsset(systemFontName, "");
GetComponent<TMP_Text>().font = fontAsset;
3. 一个自动寻找对应字体支持的fallback管理器
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Framework;
using UnityEngine;
using TMPro;
using FontWeight = TMPro.FontWeight;
using Object = UnityEngine.Object;
public static class TMProFallbackExtra
{
private static List<TMP_FontAsset> _fallbackFonts = new();
private static bool _init;
private static Coroutine _coroutine;

最低0.47元/天 解锁文章
2776

被折叠的 条评论
为什么被折叠?



