Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit e74588a

Browse files
committed
超链接部分添加了下划线
1 parent 065422f commit e74588a

File tree

9 files changed

+118
-15
lines changed

9 files changed

+118
-15
lines changed
56 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Diff for: Assets/TextInlineSprite/Materials.meta

-9
This file was deleted.

Diff for: Assets/TextInlineSprite/Script/InlieSpriteText.cs

+45
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,53 @@ protected override void OnPopulateMesh(VertexHelper toFill)
256256
}
257257
#endregion
258258

259+
#region 处理超链接的下划线--拉伸实现
260+
TextGenerator _UnderlineText = new TextGenerator();
261+
_UnderlineText.Populate("_", settings);
262+
IList<UIVertex> _TUT = _UnderlineText.verts;
263+
264+
foreach (var hrefInfo in m_HrefInfos)
265+
{
266+
if (hrefInfo.startIndex >= toFill.currentVertCount)
267+
{
268+
continue;
269+
}
270+
271+
for (int i = 0; i < hrefInfo.boxes.Count; i++)
272+
{
273+
Vector3 _StartBoxPos = new Vector3(hrefInfo.boxes[i].x, hrefInfo.boxes[i].y, 0.0f);
274+
Vector3 _EndBoxPos = _StartBoxPos + new Vector3(hrefInfo.boxes[i].width, 0.0f, 0.0f);
275+
AddUnderlineQuad(toFill, _TUT, _StartBoxPos, _EndBoxPos);
276+
}
277+
278+
}
279+
#endregion
280+
259281
}
260282

283+
#region 添加下划线
284+
void AddUnderlineQuad(VertexHelper _VToFill, IList<UIVertex> _VTUT, Vector3 _VStartPos, Vector3 _VEndPos)
285+
{
286+
Vector3[] _TUnderlinePos = new Vector3[4];
287+
_TUnderlinePos[0] = _VStartPos;
288+
_TUnderlinePos[1] = _VEndPos;
289+
_TUnderlinePos[2] = _VEndPos + new Vector3(0, fontSize * 0.2f, 0);
290+
_TUnderlinePos[3] = _VStartPos + new Vector3(0, fontSize * 0.2f, 0);
291+
292+
for (int i = 0; i < 4; ++i)
293+
{
294+
int tempVertsIndex = i & 3;
295+
m_TempVerts[tempVertsIndex] = _VTUT[i % 4];
296+
m_TempVerts[tempVertsIndex].color = Color.blue;
297+
298+
m_TempVerts[tempVertsIndex].position = _TUnderlinePos[i];
299+
300+
if (tempVertsIndex == 3)
301+
_VToFill.AddUIVertexQuad(m_TempVerts);
302+
}
303+
}
304+
#endregion
305+
261306

262307
private IList<UIVertex> _OldVerts;
263308

Diff for: Assets/TextInlineSprite/Script/InlieText.cs

+56-5
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ protected override void OnEnable()
6060
if (m_spriteGraphic != null)
6161
m_spriteAsset = m_spriteGraphic.m_spriteAsset;
6262

63+
64+
65+
6366
//启动的是 更新顶点
6467
SetVerticesDirty();
68+
69+
6570
}
6671

6772
/// <summary>
@@ -76,7 +81,6 @@ public override void SetVerticesDirty()
7681
//解析超链接
7782
m_OutputText = GetOutputText();
7883

79-
8084
//解析标签属性
8185
listTagInfor = new List<SpriteTagInfor>();
8286
m_AnimIndex = new List<int>();
@@ -116,7 +120,7 @@ public override void SetVerticesDirty()
116120
}
117121
Vector2 extents = rectTransform.rect.size;
118122
}
119-
123+
120124
readonly UIVertex[] m_TempVerts = new UIVertex[4];
121125
/// <summary>
122126
/// 绘制模型
@@ -128,7 +132,7 @@ protected override void OnPopulateMesh(VertexHelper toFill)
128132

129133
if (font == null)
130134
return;
131-
135+
132136
// We don't care if we the font Texture changes while we are doing our Update.
133137
// The end result of cachedTextGenerator will be valid for this instance.
134138
// Otherwise we can get issues like Case 619238.
@@ -156,6 +160,8 @@ protected override void OnPopulateMesh(VertexHelper toFill)
156160
//Last 4 verts are always a new line...
157161
int vertCount = verts.Count - 4;
158162

163+
164+
159165
toFill.Clear();
160166

161167
//清楚乱码
@@ -196,7 +202,7 @@ protected override void OnPopulateMesh(VertexHelper toFill)
196202
toFill.AddUIVertexQuad(m_TempVerts);
197203
}
198204
}
199-
205+
200206
//计算标签 计算偏移值后 再计算标签的值
201207
List<UIVertex> vertsTemp = new List<UIVertex>();
202208
for (int i = 0; i < vertCount; i++)
@@ -211,7 +217,7 @@ protected override void OnPopulateMesh(VertexHelper toFill)
211217

212218
//绘制图片
213219
DrawSprite();
214-
220+
215221
#region 处理超链接的包围盒
216222
// 处理超链接包围框
217223
UIVertex vert = new UIVertex();
@@ -249,8 +255,53 @@ protected override void OnPopulateMesh(VertexHelper toFill)
249255
hrefInfo.boxes.Add(new Rect(bounds.min, bounds.size));
250256
}
251257
#endregion
258+
259+
#region 处理超链接的下划线--拉伸实现
260+
TextGenerator _UnderlineText = new TextGenerator();
261+
_UnderlineText.Populate("_", settings);
262+
IList<UIVertex> _TUT = _UnderlineText.verts;
263+
264+
foreach (var hrefInfo in m_HrefInfos)
265+
{
266+
if (hrefInfo.startIndex >= toFill.currentVertCount)
267+
{
268+
continue;
269+
}
270+
271+
for (int i = 0; i < hrefInfo.boxes.Count; i++)
272+
{
273+
Vector3 _StartBoxPos = new Vector3(hrefInfo.boxes[i].x, hrefInfo.boxes[i].y, 0.0f);
274+
Vector3 _EndBoxPos = _StartBoxPos+ new Vector3(hrefInfo.boxes[i].width, 0.0f, 0.0f);
275+
AddUnderlineQuad(toFill, _TUT, _StartBoxPos, _EndBoxPos);
276+
}
277+
278+
}
279+
#endregion
252280
}
253281

282+
#region 添加下划线
283+
void AddUnderlineQuad(VertexHelper _VToFill, IList<UIVertex> _VTUT, Vector3 _VStartPos, Vector3 _VEndPos)
284+
{
285+
Vector3[] _TUnderlinePos = new Vector3[4];
286+
_TUnderlinePos[0] = _VStartPos;
287+
_TUnderlinePos[1] = _VEndPos;
288+
_TUnderlinePos[2] = _VEndPos + new Vector3(0, fontSize * 0.2f, 0);
289+
_TUnderlinePos[3] = _VStartPos + new Vector3(0, fontSize * 0.2f, 0);
290+
291+
for (int i = 0; i < 4; ++i)
292+
{
293+
int tempVertsIndex = i & 3;
294+
m_TempVerts[tempVertsIndex] = _VTUT[i % 4];
295+
m_TempVerts[tempVertsIndex].color = Color.blue;
296+
297+
m_TempVerts[tempVertsIndex].position = _TUnderlinePos[i];
298+
299+
if (tempVertsIndex == 3)
300+
_VToFill.AddUIVertexQuad(m_TempVerts);
301+
}
302+
}
303+
#endregion
304+
254305
/// <summary>
255306
/// 解析quad标签 主要清除quad乱码 获取表情的位置
256307
/// </summary>

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
</p>
44
<hr/>
55
<p>
6-
具体看scene就好,这里放两张截图
6+
unity支持最低版本为5.3,下面为展示截图,具体看scene
77
</p>
88
<p>
99
<img src="https://github.com/coding2233/TextInlineSprite/blob/master/ShotScreens/tw04_01.gif"/>
1010
</p>
1111
<p>
1212
<img src="https://github.com/coding2233/TextInlineSprite/blob/master/ShotScreens/tw04_02.gif"/>
13+
</p>
14+
<p>
15+
<img src="https://github.com/coding2233/TextInlineSprite/blob/master/ShotScreens/tw04_03.png"/>
1316
</p>

Diff for: ShotScreens/Thumbs.db

149 KB
Binary file not shown.

Diff for: ShotScreens/tw04_03.png

50.6 KB
Loading

Diff for: TextInlineSprite.userprefs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Properties StartupItem="Assembly-CSharp.csproj">
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\TextInlineSprite\Script\InlieText.cs">
4+
<Files>
5+
<File FileName="Assets\TextInlineSprite\Script\SpriteGraphic.cs" Line="1" Column="1" />
6+
<File FileName="Assets\TextInlineSprite\Script\InlieText.cs" Line="275" Column="74" />
7+
</Files>
8+
</MonoDevelop.Ide.Workbench>
9+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
10+
<BreakpointStore />
11+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
12+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
13+
</Properties>

0 commit comments

Comments
 (0)