- Home /
Load a .ttf font file as binary data
I have a .ttf font file and I want to load it as binary data. I know I can load binary data as TextAsset in Unity. But this requires the file extensions to be ".fnt" or ".bytes" (few more extensions i know). If I change the file extension, I am able to load the file as binary data in TextAsset. But I dont want to change the file type.
Is there a method in Unity where I can load the .ttf file as binary data without changing the file
Is there a way I can load the .ttf file as Font Asset in Unity and then get the raw font data from the Font Asset?
Or some other way of loading the .ttf font as binary data?
Are you able to convert those bytes into a Font object? I need to download a custom font from a server then apply it. I can download it to Application.persistentDataPath, and it is a complete file viewable in the os, but I can't load it into Unity for use as a font.
Answer by Bunny83 · Apr 26, 2017 at 09:10 PM
Just place the file in the Streaming Assets folder. Make sure you read the page carefully. The Streaming Assets folder works different depending on your target platform. That folder is ment for anything that should be shipped with your game but not treated as asset. On Android you have to use the WWW class to read those files as they are packed into the apk file itself.
Ok this worked for me after some effort. But I need to know the file names in advance while creating WWW object. Is there a way to find all files in Strea$$anonymous$$gAssets folder. Like following code works on Windows but will not work in Android. Is there a alternate for this code on Android ?
DirectoryInfo dir = new DirectoryInfo(Application.strea$$anonymous$$gAssetsPath); FileInfo[] info = dir.GetFiles("*.ttf");
I am actually curious of your method, do you $$anonymous$$d explaining how you use a text asset to change the font somewhere in your project? I want to load a font from my strea$$anonymous$$gassets and even as bytes, I just don't know what to do with it.
Your answer
Follow this Question
Related Questions
Changing a GUI Button's font in code 1 Answer
Can't able to import font 0 Answers
Getting pixel font to look decent 1 Answer
Unity Editor Fonts Display Error. 0 Answers