Font.GetOSInstalledFontNames

切换到手册
public static string[] GetOSInstalledFontNames ();

返回

string[] 该计算机上安装的所有字体的名称数组。

描述

获取该计算机上安装的字体的名称。

GetOSInstalledFontNames 可使您获取该计算机上安装的所有字体的名称。这些名称可被传入 CreateDynamicFontFromOSFont,以使用用户操作系统上安装的任何字体动态渲染文本。

using UnityEngine;
using System.Collections;

// A simple UI to display a selection of OS fonts and allow changing the UI font to any of them. public class FontSelector : MonoBehaviour { Vector2 scrollPos; string[] fonts;

void Start() { fonts = Font.GetOSInstalledFontNames(); }

void OnGUI() { scrollPos = GUILayout.BeginScrollView(scrollPos);

foreach (var font in fonts) { if (GUILayout.Button(font)) GUI.skin.font = Font.CreateDynamicFontFromOSFont(font, 12); } GUILayout.EndScrollView(); } }