CCFont

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.

Variables

asciiChars
CCFont.Char[]

ASCII characters, from '!' to '~'. Characters missing from the font have zeros for all their values.

otherChars
CCFont.Char[]

All non-ASCII characters included in the font.

pixelLineHeight
float

Original line height in pixels.

pixelScale
float

How large a pixel is, in local space. Equal to 1f / pixelLineHeight.

baseline
float

Offset of the baseline from the top of the line.

spaceAdvance
float

Amount to advance the caret for a space.

supportsKerning
bool

Whether kerning is supported by the font.

leftMargin
float

Maximum distance that spites extend to the left of the caret.

rightMargin
float

Maximum distance that spites extend to the right of the caret.

topMargin
float

Maximum distance that spites extend above the line.

bottomMargin
float

Maximum distance that spites extend below the line.

Properties

Indexer
CCFont.Char [char]

Get the data for a character in this font. Missing characters have 0s for all values.

IsValid
bool

Get whether this is a valid imported font.

Methods

UpdateAllCCText
void

Update all CCText components in the scene that use this font.

This method is expensive and creates a temporary array.

Nested Types

Char
class

Data for a single character of a bitmap sprite font.

Variables

id
int

Identifier, which is equal to the UTF-16 code of the represented character.

uMin
float

Minimum U texture coordinate value.

uMax
float

Maximum U texture coordinate value.

vMin
float

Minimum V texture coordinate value.

vMax
float

Maximum V texture coordinate value.

xOffset
float

Sprite X offset relative to caret.

yOffset
float

Sprite Y offset relative to caret.

width
float

Sprite width.

height
float

Sprite height.

advance
float

Amount to advance the caret.

kerningIds
int[]

Identifiers of characters this character has kernings for.

kerning
float[]

Kerning amounts, corresponding to kerningIds.

Methods

AdvanceWithKerning
float

Compute how much to advance the caret, taking kerning into account.

Parameters

    1. nextChar
nextChar
char

The character to compute kerning for.

Example

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.