【Unity】UI.Textで禁則処理つき改行
ルビ表示+リッチテキスト+禁則処理つき改行+文字送り。 pic.twitter.com/IcZt1Nzglh
— enu@遊宴雀2 雀-17 (@_enu) 2019年7月22日
Package
コード
[SerializeField] RubyText ruby; [SerializeField] Text body; IEnumerator Start() { var message = "{吾輩:わがはい}は猫である。<color=red>名前はまだ無い</color>。\nどこで生れたかとんと{見<color=red>当:けんとう}がつか</color>ぬ。何でも薄暗いじめじめした所で<color=red>ニャーニャー</color>泣いていた事だけは記憶している。"; var stringWithRuby = StringWithRuby.Parse(message) .FoldTag() .WrapWithHyphenation(body, new HyphenationJpns.Ruler()); while (true) { for (int i = 0; i < stringWithRuby.body.Length; ++i) { if (stringWithRuby.body[i] == '\n') { continue; } var sub = stringWithRuby.Substring(0, i).UnfoldTag(); ruby.Set(sub); body.text = sub.body; yield return new WaitForSeconds(0.05f); } yield return new WaitForSeconds(1f); } }