@@ -111,6 +111,7 @@ protected override void OnPopulateMesh(VertexHelper toFill)
111
111
//更新顶点位置&去掉乱码uv
112
112
m_DisableFontTextureRebuiltCallback = true ;
113
113
int index = - 1 ;
114
+ //emoji
114
115
for ( int i = 0 ; i < _spriteInfo . Count ; i ++ )
115
116
{
116
117
index = _spriteInfo [ i ] . Index ;
@@ -128,6 +129,39 @@ protected override void OnPopulateMesh(VertexHelper toFill)
128
129
129
130
}
130
131
}
132
+ // 处理超链接包围框
133
+ for ( int i = 0 ; i < _listHrefInfos . Count ; i ++ )
134
+ {
135
+ _listHrefInfos [ i ] . Boxes . Clear ( ) ;
136
+ if ( _listHrefInfos [ i ] . StartIndex >= toFill . currentVertCount )
137
+ continue ;
138
+
139
+ toFill . PopulateUIVertex ( ref _tempVertex , _listHrefInfos [ i ] . StartIndex ) ;
140
+ // 将超链接里面的文本顶点索引坐标加入到包围框
141
+ var pos = _tempVertex . position ;
142
+ var bounds = new Bounds ( pos , Vector3 . zero ) ;
143
+ for ( int j = _listHrefInfos [ i ] . StartIndex + 1 ; j < _listHrefInfos [ i ] . EndIndex ; j ++ )
144
+ {
145
+ if ( j >= toFill . currentVertCount )
146
+ {
147
+ break ;
148
+ }
149
+ toFill . PopulateUIVertex ( ref _tempVertex , j ) ;
150
+ pos = _tempVertex . position ;
151
+ if ( pos . x < bounds . min . x )
152
+ {
153
+ // 换行重新添加包围框
154
+ _listHrefInfos [ i ] . Boxes . Add ( new Rect ( bounds . min , bounds . size ) ) ;
155
+ bounds = new Bounds ( pos , Vector3 . zero ) ;
156
+ }
157
+ else
158
+ {
159
+ bounds . Encapsulate ( pos ) ; // 扩展包围框
160
+ }
161
+ }
162
+ //添加包围盒
163
+ _listHrefInfos [ i ] . Boxes . Add ( new Rect ( bounds . min , bounds . size ) ) ;
164
+ }
131
165
m_DisableFontTextureRebuiltCallback = false ;
132
166
133
167
UpdateDrawnSprite ( ) ;
@@ -207,8 +241,8 @@ void CalcBoundsInfo(List<Vector3> listVertsPos, VertexHelper toFill,TextGenerati
207
241
pos = listVertsPos [ i ] ;
208
242
if ( pos . x < bounds . min . x )
209
243
{
210
- // 换行重新添加包围框
211
- hrefInfo . Boxes . Add ( new Rect ( bounds . min , bounds . size ) ) ;
244
+ // 换行重新添加包围框
245
+ hrefInfo . Boxes . Add ( new Rect ( bounds . min , bounds . size ) ) ;
212
246
bounds = new Bounds ( pos , Vector3 . zero ) ;
213
247
}
214
248
else
@@ -259,8 +293,10 @@ private string GetOutputText(string inputText)
259
293
if ( string . IsNullOrEmpty ( inputText ) )
260
294
return "" ;
261
295
296
+ //回收各种对象
262
297
ReleaseSpriteTageInfo ( ) ;
263
- _textBuilder . Remove ( 0 , _textBuilder . Length ) ;
298
+ ReleaseHrefInfos ( ) ;
299
+ _textBuilder . Remove ( 0 , _textBuilder . Length ) ;
264
300
int textIndex = 0 ;
265
301
266
302
foreach ( Match match in _inputTagRegex . Matches ( inputText ) )
@@ -276,16 +312,15 @@ private string GetOutputText(string inputText)
276
312
_textBuilder . Append ( "<color=blue>" ) ;
277
313
int startIndex = _textBuilder . Length * 4 ;
278
314
_textBuilder . Append ( "[" + match . Groups [ 2 ] . Value + "]" ) ;
279
- int endIndex = _textBuilder . Length * 4 - 2 ;
315
+ int endIndex = _textBuilder . Length * 4 - 1 ;
280
316
_textBuilder . Append ( "</color>" ) ;
281
317
282
- var hrefInfo = new HrefInfo
283
- {
284
- Id = Mathf . Abs ( tempId ) ,
285
- StartIndex = startIndex , // 超链接里的文本起始顶点索引
286
- EndIndex = endIndex ,
287
- Name = match . Groups [ 2 ] . Value
288
- } ;
318
+
319
+ var hrefInfo = Pool < HrefInfo > . Get ( ) ;
320
+ hrefInfo . Id = Mathf . Abs ( tempId ) ;
321
+ hrefInfo . StartIndex = startIndex ; // 超链接里的文本起始顶点索引
322
+ hrefInfo . EndIndex = endIndex ;
323
+ hrefInfo . Name = match . Groups [ 2 ] . Value ;
289
324
_listHrefInfos . Add ( hrefInfo ) ;
290
325
291
326
}
@@ -322,7 +357,7 @@ private string GetOutputText(string inputText)
322
357
#endregion
323
358
324
359
#region 超链接信息类
325
- private class HrefInfo
360
+ public class HrefInfo
326
361
{
327
362
public int Id ;
328
363
@@ -358,6 +393,7 @@ public void OnPointerClick(PointerEventData eventData)
358
393
}
359
394
#endregion
360
395
396
+ //回收SpriteTagInfo
361
397
private void ReleaseSpriteTageInfo ( )
362
398
{
363
399
//记录之前的信息
@@ -368,13 +404,49 @@ private void ReleaseSpriteTageInfo()
368
404
}
369
405
_spriteInfo . Clear ( ) ;
370
406
}
407
+ //回收超链接的信息
408
+ private void ReleaseHrefInfos ( )
409
+ {
410
+ for ( int i = 0 ; i < _listHrefInfos . Count ; i ++ )
411
+ {
412
+ Pool < HrefInfo > . Release ( _listHrefInfos [ i ] ) ;
413
+ }
414
+ _listHrefInfos . Clear ( ) ;
415
+ }
371
416
372
417
#if UNITY_EDITOR
418
+ Vector3 [ ] _textWolrdVertexs = new Vector3 [ 4 ] ;
373
419
private void OnDrawGizmos ( )
374
420
{
375
- Gizmos . color = Color . yellow ;
376
-
377
- for ( int i = 0 ; i < _spriteInfo . Count ; i ++ )
421
+ //text
422
+ Gizmos . color = Color . white ;
423
+ rectTransform . GetWorldCorners ( _textWolrdVertexs ) ;
424
+ Gizmos . DrawLine ( _textWolrdVertexs [ 0 ] , _textWolrdVertexs [ 1 ] ) ;
425
+ Gizmos . DrawLine ( _textWolrdVertexs [ 1 ] , _textWolrdVertexs [ 2 ] ) ;
426
+ Gizmos . DrawLine ( _textWolrdVertexs [ 2 ] , _textWolrdVertexs [ 3 ] ) ;
427
+ Gizmos . DrawLine ( _textWolrdVertexs [ 3 ] , _textWolrdVertexs [ 0 ] ) ;
428
+
429
+ //href
430
+ Gizmos . color = Color . green ;
431
+ for ( int i = 0 ; i < _listHrefInfos . Count ; i ++ )
432
+ {
433
+ for ( int j = 0 ; j < _listHrefInfos [ i ] . Boxes . Count ; j ++ )
434
+ {
435
+ Rect rect = _listHrefInfos [ i ] . Boxes [ j ] ;
436
+ Vector3 point00 = Utility . TransformPoint2World ( transform , rect . position ) ;
437
+ Vector3 point01 = Utility . TransformPoint2World ( transform , new Vector3 ( rect . x + rect . width , rect . y ) ) ;
438
+ Vector3 point02 = Utility . TransformPoint2World ( transform , new Vector3 ( rect . x + rect . width , rect . y + rect . height ) ) ;
439
+ Vector3 point03 = Utility . TransformPoint2World ( transform , new Vector3 ( rect . x , rect . y + rect . height ) ) ;
440
+ Gizmos . DrawLine ( point00 , point01 ) ;
441
+ Gizmos . DrawLine ( point01 , point02 ) ;
442
+ Gizmos . DrawLine ( point02 , point03 ) ;
443
+ Gizmos . DrawLine ( point03 , point00 ) ;
444
+ }
445
+ }
446
+
447
+ //sprite
448
+ Gizmos . color = Color . yellow ;
449
+ for ( int i = 0 ; i < _spriteInfo . Count ; i ++ )
378
450
{
379
451
Gizmos . DrawLine ( _spriteInfo [ i ] . Pos [ 0 ] , _spriteInfo [ i ] . Pos [ 1 ] ) ;
380
452
Gizmos . DrawLine ( _spriteInfo [ i ] . Pos [ 1 ] , _spriteInfo [ i ] . Pos [ 2 ] ) ;
0 commit comments