Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active October 3, 2017 13:50
Show Gist options
  • Select an option

  • Save dskjal/6e01eeb543c3cadf209ec5e6fa503cc4 to your computer and use it in GitHub Desktop.

Select an option

Save dskjal/6e01eeb543c3cadf209ec5e6fa503cc4 to your computer and use it in GitHub Desktop.
uGUI で改行位置を取得する
// uGUI Text の Text スクリプトを取得
var t = GameObject.Find("textbox").gameObject.GetComponent<Text>();
// レンダリングするテキスト
t.text = "abcdefghijklmnopqrstuvwxyz01234567890";
// 改行位置等を計算
var generator = new TextGenerator();
var rt = t.GetComponent<RectTransform>();
var size = new Vector2(rt.rect.width, rt.rect.height);
generator.Populate(t.text, t.GetGenerationSettings(size));
// 改行位置を取得
foreach(var l in generator.lines){
Debug.log(l.startCharIdx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment