@@ -48,6 +48,7 @@ private InlineManager Manager
4848 List < SpriteTagInfo > RenderTagList ;
4949
5050 private bool needupdate ;
51+ private bool updatespace = true ;
5152 private string _OutputText = "" ;
5253
5354 #region 超链接
@@ -183,6 +184,7 @@ void OnDrawGizmos()
183184 Vector3 textsize = transform . TransformDirection ( size ) ;
184185
185186 Vector3 fixpos = transform . position ;
187+ //可简化
186188 if ( this . alignment == TextAnchor . LowerCenter )
187189 {
188190 fixpos += new Vector3 ( 0 , - 0.5f * ( fixsize . y - textsize . y ) , 0 ) ;
@@ -234,7 +236,7 @@ protected override void OnEnable()
234236 {
235237 base . OnEnable ( ) ;
236238
237- supportRichText = true ;
239+ // supportRichText = true;
238240 SetVerticesDirty ( ) ;
239241 }
240242
@@ -249,16 +251,16 @@ public override void SetVerticesDirty()
249251 }
250252
251253 string outtext = GetOutputText ( m_Text ) ;
252- if ( RenderTagList != null && RenderTagList . Count > 0 )
254+ if ( RenderTagList != null && RenderTagList . Count > 0 )
253255 {
254256 _OutputText = outtext ;
255- needupdate = true ;
257+ needupdate = true ;
256258 _pw = null ;
257259 }
258260 else
259261 {
260262 _OutputText = m_Text ;
261- needupdate = true ;
263+ needupdate = true ;
262264 _pw = null ;
263265 }
264266 }
@@ -400,6 +402,7 @@ void CalcQuadInfo()
400402 {
401403 if ( RenderTagList != null )
402404 {
405+ float height = this . preferredHeight / 2 ;
403406 for ( int i = 0 ; i < RenderTagList . Count ; ++ i )
404407 {
405408 SpriteTagInfo info = RenderTagList [ i ] ;
@@ -409,17 +412,17 @@ void CalcQuadInfo()
409412
410413 Vector3 p1 = _listVertsPos [ pos ] ;
411414
412- info . _Pos [ 0 ] = p1 ;
413- info . _Pos [ 1 ] = _listVertsPos [ pos + 1 ] ;
414- info . _Pos [ 2 ] = _listVertsPos [ pos + 2 ] ;
415- info . _Pos [ 3 ] = _listVertsPos [ pos + 3 ] ;
416-
417- //info._Pos[0] = p1 + new Vector3(0, info._Size.y, 0) ;
418- //info._Pos[1] = p1 + new Vector3(info._Size.x, info._Size.y, 0);
419- // info._Pos[2 ] = p1 + new Vector3(info._Size.x, 0 , 0);
420- // info._Pos[3 ] = p1;
421-
422-
415+ // info._Pos[0] = p1 ;
416+ // info._Pos[1] = _listVertsPos[pos+1];
417+ // info._Pos[2] = _listVertsPos[pos+2];
418+ // info._Pos[3] = _listVertsPos[pos+3];
419+ //int cid = ((int)alignment) /3;
420+ //int rid = ((int)alignment) % 3 ;
421+
422+ info . _Pos [ 0 ] = p1 + new Vector3 ( 0 , info . _Size . y / 2 + height , 0 ) ;
423+ info . _Pos [ 1 ] = p1 + new Vector3 ( info . _Size . x , info . _Size . y / 2 + height , 0 ) ;
424+ info . _Pos [ 2 ] = p1 + new Vector3 ( info . _Size . x , height - info . _Size . y / 2 , 0 ) ;
425+ info . _Pos [ 3 ] = p1 + new Vector3 ( 0 , height - info . _Size . y / 2 , 0 ) ;
423426 }
424427 }
425428
@@ -574,40 +577,42 @@ bool ParseEmoji(string newInfo,int Index, int Id, string TagName, Match match, r
574577 _textBuilder . Append ( newInfo . Substring ( _textIndex , match . Index - _textIndex ) ) ;
575578 int _tempIndex = _textBuilder . Length * 4 ;
576579
577- float autosize = Mathf . Min ( tagSprites . size , this . rectTransform . rect . height - 8 ) ;
580+ float h = Mathf . Max ( 1 , this . rectTransform . rect . height - 8 ) ;
581+ float autosize = Mathf . Min ( h , tagSprites . size ) ;
582+ if ( _SpaceGen == null )
583+ {
584+ _SpaceGen = new TextGenerator ( ) ;
585+
586+ }
578587
579- if ( _SpaceGen == null )
588+ if ( updatespace )
580589 {
581590 Vector2 extents = rectTransform . rect . size ;
582-
583591 TextGenerationSettings settings = GetGenerationSettings ( extents ) ;
592+ _SpaceGen . Populate ( " " , settings ) ;
593+ updatespace = false ;
594+ }
584595
585- _SpaceGen = new TextGenerator ( ) ;
586- //two sapceing
587- _SpaceGen . Populate ( " " , settings ) ;
596+ IList < UIVertex > spaceverts = _SpaceGen . verts ;
597+ float spacewid = spaceverts [ 1 ] . position . x - spaceverts [ 0 ] . position . x ;
598+ float spaceheight = spaceverts [ 0 ] . position . y - spaceverts [ 3 ] . position . y ;
599+ float spacesize = Mathf . Max ( spacewid , spaceheight ) ;
600+
601+ int fillspacecnt = Mathf . RoundToInt ( autosize / spacesize ) ;
602+ if ( autosize > spacesize )
603+ {
604+ fillspacecnt = Mathf . RoundToInt ( ( autosize ) / ( spacesize ) ) ;
605+ }
606+ else
607+ {
608+ fillspacecnt = Mathf . RoundToInt ( autosize / spacesize ) ;
609+ }
610+ for ( int i = 0 ; i < fillspacecnt ; i ++ )
611+ {
612+ _textBuilder . Append ( " " ) ;
588613 }
589614
590- //IList<UIVertex> spaceverts = _SpaceGen.verts;
591- //float spacewid = spaceverts[1].position.x - spaceverts[0].position.x;
592- //float spaceheight = spaceverts[0].position.y - spaceverts[3].position.y;
593- //float deltawid = spaceverts[4].position.x - spaceverts[1].position.x;
594- //float spacesize = Mathf.Max(spacewid, spaceheight);
595-
596- //int fillspacecnt = Mathf.RoundToInt( autosize / spacesize);
597- //if(autosize > spacesize)
598- //{
599- // fillspacecnt = Mathf.RoundToInt((autosize + deltawid) / (spacesize+ deltawid));
600- //}
601- //else
602- //{
603- // fillspacecnt = Mathf.RoundToInt(autosize / spacesize);
604- //}
605- //for(int i =0; i < fillspacecnt;i++)
606- //{
607- // _textBuilder.Append(" ");
608- //}
609-
610- _textBuilder . AppendFormat ( "<quad material=0 x={0} y={1} size={2} width={3} />" , tagSprites . x , tagSprites . y , autosize , tagSprites . width ) ;
615+ //_textBuilder.AppendFormat("<quad material=0 x={0} y={1} size={2} width={3} />", tagSprites.x, tagSprites.y, autosize, tagSprites.width);
611616
612617 if ( RenderTagList . Count > Index )
613618 {
@@ -718,6 +723,8 @@ private string GetOutputText(string newinfo)
718723 }
719724
720725 _textBuilder . Append ( newinfo . Substring ( _textIndex , newinfo . Length - _textIndex ) ) ;
726+
727+ updatespace = true ;
721728 return _textBuilder . ToString ( ) ;
722729 }
723730
0 commit comments