23 [SerializeField]
private bool m_Enable =
false;
24 [SerializeField]
private float m_MaxWidth = 0;
25 [SerializeField]
private float m_Gap = 1;
26 [SerializeField]
private string m_Suffix =
"...";
35 get {
return m_Enable; }
36 set {
if (PropertyUtil.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
45 get {
return m_MaxWidth; }
46 set {
if (PropertyUtil.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
56 set {
if (PropertyUtil.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
65 get {
return m_Suffix; }
66 set {
if (PropertyUtil.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
70 private float m_RelatedTextWidth = 0;
82 public void Copy(TextLimit textLimit)
90 public void SetRelatedText(ChartText txt,
float labelWidth)
93 m_RelatedTextWidth = labelWidth;
97 public string GetLimitContent(
string content)
99 float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
100 if (m_RelatedText ==
null || checkWidth <= 0)
return content;
105 float len = m_RelatedText.GetPreferredWidth(content);
106 float suffixLen = m_RelatedText.GetPreferredWidth(
suffix);
107 if (len >= checkWidth - m_Gap * 2)
109 return content.Substring(0, GetAdaptLength(content, suffixLen)) +
suffix;
123 private int GetAdaptLength(
string content,
float suffixLen)
126 int middle = content.Length / 2;
127 int end = content.Length;
128 float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
129 float limit = checkWidth - m_Gap * 2 - suffixLen;
130 if (limit < 0)
return 0;
132 while (len != limit && middle != start)
134 len = m_RelatedText.GetPreferredWidth(content.Substring(0, middle));
139 else if (len > limit)
147 middle = (start + end) / 2;