Specifically it's Font.CreateDynamicFontFromOSFont(), use this script attached to an empty GameObject in the scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestFontTexture : MonoBehaviour {
void Start ()
{
var font = Font.CreateDynamicFontFromOSFont("Consolas", 12);
font.RequestCharactersInTexture("HelloWorld", 20);
SaveTexture2PNG("./fontTexture.png", (Texture2D)font.material.mainTexture);
}
void Update ()
{
}
void SaveTexture2PNG(string path, Texture2D tex)
{
byte[] bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
}
}
After click play it should create a fontTexture.png file containing character glyphs in the Assets folder, but only in editor though. In athe built game, it just created a completely black image.
sinceSince it's OS concerned, I'm using Windows 7 with font Consolas installed and Unity 5.6.5f.
How to make it work in a built game?