Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyubuns/8658fa4c601c620928a3a9063a915de8 to your computer and use it in GitHub Desktop.
Save kyubuns/8658fa4c601c620928a3a9063a915de8 to your computer and use it in GitHub Desktop.
var fontAsset = AssetDatabase.LoadAssetAtPath<Font>(fontPath);
var settings = new TextGenerationSettings
{
generationExtents = Vector2.zero,
textAnchor = TextAnchor.MiddleCenter,
alignByGeometry = false,
scaleFactor = 1.0f,
color = Color.white,
font = fontAsset,
fontSize = Mathf.RoundToInt(fontSize),
pivot = Vector2.zero,
richText = false,
lineSpacing = 0,
fontStyle = FontStyle.Normal,
resizeTextForBestFit = false,
updateBounds = false,
horizontalOverflow = HorizontalWrapMode.Overflow,
verticalOverflow = VerticalWrapMode.Overflow
};
var textGenerator = new TextGenerator();
var width = textGenerator.GetPreferredWidth(rawText, settings);
var height = textGenerator.GetPreferredHeight(rawText, settings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment