Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sassembla/a51fc0d85672e2f3233607c9e0b6cac6 to your computer and use it in GitHub Desktop.
Save sassembla/a51fc0d85672e2f3233607c9e0b6cac6 to your computer and use it in GitHub Desktop.
// TMProのコンポーネント TMPro.TextMeshProUGUI textComponentというのがあったとして
textComponent.text = text;
// textComponentに対してwidthをセットする必要がある。高さは無限設定でOK
textComponent.rectTransform.sizeDelta = new Vector2(viewWidth, float.PositiveInfinity);
// このメソッドは、コンポーネントがgameobjectにアタッチされて、かつgameobjectがcanvasに乗っている場合のみ動作する。
var textInfos = textComponent.GetTextInfo(text);
// 各行の要素とパラメータを取得する。
var tmGeneratorLines = textInfos.lineInfo;
var lineSpacing = textComponent.lineSpacing;
var tmLineCount = textInfos.lineCount;
@sassembla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment