@@ -9,18 +9,18 @@ namespace Hypertext
99 public abstract class HypertextBase : Text , IPointerClickHandler
1010 {
1111 Canvas rootCanvas ;
12- Canvas RootCanvas { get { return rootCanvas ?? ( rootCanvas = GetComponentInParent < Canvas > ( ) ) ; } }
12+ Canvas RootCanvas => rootCanvas ?? ( rootCanvas = GetComponentInParent < Canvas > ( ) ) ;
1313
1414 const int CharVerts = 6 ;
1515 readonly List < Span > spans = new List < Span > ( ) ;
1616 static readonly ObjectPool < List < UIVertex > > verticesPool = new ObjectPool < List < UIVertex > > ( null , l => l . Clear ( ) ) ;
1717
1818 struct Span
1919 {
20- public int StartIndex ;
21- public int Length ;
22- public Color Color ;
23- public Action < string > Callback ;
20+ public readonly int StartIndex ;
21+ public readonly int Length ;
22+ public readonly Color Color ;
23+ public readonly Action < string > Callback ;
2424 public List < Rect > BoundingBoxes ;
2525
2626 public Span ( int startIndex , int endIndex , Color color , Action < string > callback )
@@ -96,12 +96,12 @@ void Modify(ref List<UIVertex> vertices)
9696 {
9797 var verticesCount = vertices . Count ;
9898
99- for ( int i = 0 ; i < spans . Count ; i ++ )
99+ for ( var i = 0 ; i < spans . Count ; i ++ )
100100 {
101101 var span = spans [ i ] ;
102102 var endIndex = span . StartIndex + span . Length ;
103103
104- for ( int textIndex = span . StartIndex ; textIndex < endIndex ; textIndex ++ )
104+ for ( var textIndex = span . StartIndex ; textIndex < endIndex ; textIndex ++ )
105105 {
106106 var vertexStartIndex = textIndex * CharVerts ;
107107 if ( vertexStartIndex + CharVerts > verticesCount )
@@ -112,7 +112,7 @@ void Modify(ref List<UIVertex> vertices)
112112 var min = Vector2 . one * float . MaxValue ;
113113 var max = Vector2 . one * float . MinValue ;
114114
115- for ( int vertexIndex = 0 ; vertexIndex < CharVerts ; vertexIndex ++ )
115+ for ( var vertexIndex = 0 ; vertexIndex < CharVerts ; vertexIndex ++ )
116116 {
117117 var vertex = vertices [ vertexStartIndex + vertexIndex ] ;
118118 vertex . color = span . Color ;
@@ -141,7 +141,7 @@ void Modify(ref List<UIVertex> vertices)
141141 }
142142 }
143143
144- span . BoundingBoxes . Add ( new Rect { min = min , max = max } ) ;
144+ span . BoundingBoxes . Add ( new Rect { min = min , max = max } ) ;
145145 }
146146
147147 // 文字ごとのバウンディングボックスを行ごとのバウンディングボックスにまとめる
@@ -150,18 +150,20 @@ void Modify(ref List<UIVertex> vertices)
150150 }
151151 }
152152
153- List < Rect > CalculateLineBoundingBoxes ( List < Rect > charBoundingBoxes )
153+ static List < Rect > CalculateLineBoundingBoxes ( List < Rect > charBoundingBoxes )
154154 {
155155 var lineBoundingBoxes = new List < Rect > ( ) ;
156156 var lineStartIndex = 0 ;
157157
158- for ( int i = 1 ; i < charBoundingBoxes . Count ; i ++ )
158+ for ( var i = 1 ; i < charBoundingBoxes . Count ; i ++ )
159159 {
160- if ( charBoundingBoxes [ i ] . xMin < charBoundingBoxes [ i - 1 ] . xMin )
160+ if ( charBoundingBoxes [ i ] . xMin >= charBoundingBoxes [ i - 1 ] . xMin )
161161 {
162- lineBoundingBoxes . Add ( CalculateAABB ( charBoundingBoxes . GetRange ( lineStartIndex , i - lineStartIndex ) ) ) ;
163- lineStartIndex = i ;
162+ continue ;
164163 }
164+
165+ lineBoundingBoxes . Add ( CalculateAABB ( charBoundingBoxes . GetRange ( lineStartIndex , i - lineStartIndex ) ) ) ;
166+ lineStartIndex = i ;
165167 }
166168
167169 if ( lineStartIndex < charBoundingBoxes . Count )
@@ -172,12 +174,12 @@ List<Rect> CalculateLineBoundingBoxes(List<Rect> charBoundingBoxes)
172174 return lineBoundingBoxes ;
173175 }
174176
175- Rect CalculateAABB ( List < Rect > rects )
177+ static Rect CalculateAABB ( IReadOnlyList < Rect > rects )
176178 {
177179 var min = Vector2 . one * float . MaxValue ;
178180 var max = Vector2 . one * float . MinValue ;
179181
180- for ( int i = 0 ; i < rects . Count ; i ++ )
182+ for ( var i = 0 ; i < rects . Count ; i ++ )
181183 {
182184 if ( rects [ i ] . xMin < min . x )
183185 {
@@ -200,7 +202,7 @@ Rect CalculateAABB(List<Rect> rects)
200202 }
201203 }
202204
203- return new Rect { min = min , max = max } ;
205+ return new Rect { min = min , max = max } ;
204206 }
205207
206208 Vector3 CalculateLocalPosition ( Vector3 position , Camera pressEventCamera )
@@ -215,7 +217,7 @@ Vector3 CalculateLocalPosition(Vector3 position, Camera pressEventCamera)
215217 return transform . InverseTransformPoint ( position ) ;
216218 }
217219
218- var localPosition = Vector2 . zero ;
220+ Vector2 localPosition ;
219221 RectTransformUtility . ScreenPointToLocalPointInRectangle ( rectTransform , position , pressEventCamera , out localPosition ) ;
220222 return localPosition ;
221223 }
@@ -224,9 +226,9 @@ void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
224226 {
225227 var localPosition = CalculateLocalPosition ( eventData . position , eventData . pressEventCamera ) ;
226228
227- for ( int s = 0 ; s < spans . Count ; s ++ )
229+ for ( var s = 0 ; s < spans . Count ; s ++ )
228230 {
229- for ( int b = 0 ; b < spans [ s ] . BoundingBoxes . Count ; b ++ )
231+ for ( var b = 0 ; b < spans [ s ] . BoundingBoxes . Count ; b ++ )
230232 {
231233 if ( spans [ s ] . BoundingBoxes [ b ] . Contains ( localPosition ) )
232234 {
0 commit comments