class : ScriptableObject
CCFont contains data for a bitmap sprite font. It supports all non-control characters in the Basic Multilingual Plane.
While font data is typically imported, you could create and modify it through scripting. If you do, it's your responsibility to keep the data correct and complete.
CCFont.Char[]
ASCII characters, from '!'
to '~'
.
Characters missing from the font have zeros for all their values.
CCFont.Char[]
All non-ASCII characters included in the font.
float
Original line height in pixels.
float
How large a pixel is, in local space.
Equal to 1f / pixelLineHeight
.
float
Offset of the baseline from the top of the line.
float
Amount to advance the caret for a space.
bool
Whether kerning is supported by the font.
float
Maximum distance that spites extend to the left of the caret.
float
Maximum distance that spites extend to the right of the caret.
float
Maximum distance that spites extend above the line.
float
Maximum distance that spites extend below the line.
CCFont.Char [char]
Get the data for a character in this font. Missing characters have 0s for all values.
bool
Get whether this is a valid imported font.
void
Update all CCText
components in the scene that use this font.
This method is expensive and creates a temporary array.
class
Data for a single character of a bitmap sprite font.
int
Identifier, which is equal to the UTF-16 code of the represented character.
float
Minimum U texture coordinate value.
float
Maximum U texture coordinate value.
float
Minimum V texture coordinate value.
float
Maximum V texture coordinate value.
float
Sprite X offset relative to caret.
float
Sprite Y offset relative to caret.
float
Sprite width.
float
Sprite height.
float
Amount to advance the caret.
int[]
Identifiers of characters this character has kernings for.
float[]
Kerning amounts, corresponding to kerningIds.
float
Compute how much to advance the caret, taking kerning into account.
char
The character to compute kerning for.
using System.Text; using UnityEditor; using UnityEngine; public class CCFontExample { [MenuItem("Assets/Print Font Characters", true)] public static bool ValidatePrintFontCharacters () { return Selection.activeObject as CCFont != null; } [MenuItem("Assets/Print Font Characters")] public static void PrintFontCharacters () { CCFont font = Selection.activeObject as CCFont; if(font == null){ Debug.Log("Not a CCFont selected."); return; } if(!font.IsValid){ Debug.Log("Not a valid imported font."); return; } StringBuilder sb = new StringBuilder(100); foreach(CCFont.Char c in font.asciiChars){ if(c.id != 0){ sb.Append((char)c.id); } } foreach(CCFont.Char c in font.otherChars){ sb.Append((char)c.id); } Debug.Log(sb); } }The above code defines a menu item for printing all characters supported by the currently selected font to the Unity console.
Create a font and import an FNT file. With the font selected, go to Assets / Print Font Characters. You will see all characters of the font appear in the console.