【Unity】TextMeshPro のテキストサイズを取得する
![](https://kazupon.org/wp-content/uploads/2020/01/unity_logologo.png)
RectTransform のRect ではなく、文字列全体の幅、高さを得る。
// TextMeshProUGUI コンポーネントからサイズは取れます。
var textMeshProUGUI = this.GetComponent<TextMeshProUGUI>();
// サイズ取得
var rect = new Vector2(textMeshProUGUI.preferredWidth,textMeshProUGUI.preferredHeight);
// 確認
Debug.Log(rect);