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

Commit 7af304f

Browse files
committed
为超链接添加id以区分同样名称的链接
1 parent 5e2e5f2 commit 7af304f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed
0 Bytes
Binary file not shown.

Assets/TextInlineSprite/Examples/Scripts/ClickTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ void OnDisable()
2929
_text.OnHrefClick.RemoveListener(OnHrefClick);
3030
}
3131

32-
private void OnHrefClick(string hrefName)
32+
private void OnHrefClick(string hrefName,int id)
3333
{
34-
Debug.Log("点击了 " + hrefName);
34+
Debug.Log("点击了 " + hrefName+" id:"+id);
3535
// Application.OpenURL("www.baidu.com");
3636
}
3737
}

Assets/TextInlineSprite/Scripts/InlineText.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InlineText : Text, IPointerClickHandler
3131

3232
#region 超链接
3333
[System.Serializable]
34-
public class HrefClickEvent : UnityEvent<string> { }
34+
public class HrefClickEvent : UnityEvent<string,int> { }
3535
//点击事件监听
3636
public HrefClickEvent OnHrefClick = new HrefClickEvent();
3737
// 超链接信息列表
@@ -323,11 +323,11 @@ private string GetOutputText()
323323
foreach (Match match in _InputTagRegex.Matches(text))
324324
{
325325
int _tempID = 0;
326-
if (!string.IsNullOrEmpty(match.Groups[1].Value))
326+
if (!string.IsNullOrEmpty(match.Groups[1].Value)&& !match.Groups[1].Value.Equals("-"))
327327
_tempID = int.Parse(match.Groups[1].Value);
328328
string _tempTag = match.Groups[2].Value;
329329
//更新超链接
330-
if (_tempID == -1)
330+
if (_tempID <0 )
331331
{
332332
_textBuilder.Append(text.Substring(_textIndex, match.Index - _textIndex));
333333
_textBuilder.Append("<color=blue>");
@@ -338,6 +338,7 @@ private string GetOutputText()
338338

339339
var hrefInfo = new HrefInfo
340340
{
341+
id = Mathf.Abs(_tempID),
341342
startIndex = _startIndex, // 超链接里的文本起始顶点索引
342343
endIndex = _endIndex,
343344
name = match.Groups[2].Value
@@ -380,6 +381,8 @@ private string GetOutputText()
380381
#region 超链接信息类
381382
private class HrefInfo
382383
{
384+
public int id;
385+
383386
public int startIndex;
384387

385388
public int endIndex;
@@ -406,7 +409,7 @@ public void OnPointerClick(PointerEventData eventData)
406409
{
407410
if (boxes[i].Contains(lp))
408411
{
409-
OnHrefClick.Invoke(hrefInfo.name);
412+
OnHrefClick.Invoke(hrefInfo.name, hrefInfo.id);
410413
return;
411414
}
412415
}

0 commit comments

Comments
 (0)