@@ -14,19 +14,15 @@ public abstract class HypertextBase : Text, IPointerClickHandler
1414 struct ClickableEntry
1515 {
1616 public int WordStartIndex ;
17- public int WordLength ;
18-
1917 public string Word ;
2018 public Color Color ;
2119 public Action < string > OnClick ;
22-
2320 public List < Rect > Rects ;
2421
25- public ClickableEntry ( string word , int startIndex , int wordLength , Color color , Action < string > onClick )
22+ public ClickableEntry ( string word , int startIndex , Color color , Action < string > onClick )
2623 {
2724 Word = word ;
2825 WordStartIndex = startIndex ;
29- WordLength = wordLength ;
3026 Color = color ;
3127 OnClick = onClick ;
3228 Rects = new List < Rect > ( ) ;
@@ -52,7 +48,7 @@ protected void RegisterClickable(int wordStartIndex, int wordLength, Color color
5248 return ;
5349 }
5450
55- _entries . Add ( new ClickableEntry ( text . Substring ( wordStartIndex , wordLength ) , wordStartIndex , wordLength , color , onClick ) ) ;
51+ _entries . Add ( new ClickableEntry ( text . Substring ( wordStartIndex , wordLength ) , wordStartIndex , color , onClick ) ) ;
5652 }
5753
5854 /// <summary>
@@ -94,7 +90,7 @@ void Modify(ref List<UIVertex> vertices)
9490 {
9591 var entry = _entries [ i ] ;
9692
97- for ( int textIndex = entry . WordStartIndex , wordEndIndex = entry . WordStartIndex + entry . WordLength ; textIndex < wordEndIndex ; textIndex ++ )
93+ for ( int textIndex = entry . WordStartIndex , wordEndIndex = entry . WordStartIndex + entry . Word . Length ; textIndex < wordEndIndex ; textIndex ++ )
9894 {
9995 var vertexStartIndex = textIndex * CharVertsNum ;
10096 if ( vertexStartIndex + CharVertsNum > verticesCount )
@@ -221,18 +217,19 @@ public void OnPointerClick(PointerEventData eventData)
221217
222218 foreach ( var entry in _entries )
223219 {
220+ if ( entry . OnClick == null )
221+ {
222+ continue ;
223+ }
224+
224225 foreach ( var rect in entry . Rects )
225226 {
226227 if ( ! rect . Contains ( localPosition ) )
227228 {
228229 continue ;
229230 }
230231
231- if ( entry . OnClick != null )
232- {
233- entry . OnClick ( entry . Word ) ;
234- }
235-
232+ entry . OnClick ( entry . Word ) ;
236233 break ;
237234 }
238235 }
0 commit comments