using UnityEngine;
using System.Collections;
<summary>
</summary>
public class UILabelHeightFitter : MonoBehaviour {
<summary>
</summary>
public UILabel label;
private string beforeText = "";
void Update () {
if (label.text != beforeText) {
ResizeHeight();
beforeText = label.text;
}
}
<summary>
====
</summary>
void ResizeHeight () {
int line = 1;
int chara = 0;
int maxChara = label.width / (label.fontSize + label.spacingX);
string text = label.text;
for (int i = 0; i < text.Length; i++) {
if (text[i] != '\n') {
chara++;
if (chara >= maxChara) {
chara = 0;
line++;
}
} else {
chara = 0;
line++;
}
}
label.height = (label.fontSize + label.spacingY) * line;
}
}