protected string ParseUnderlineTag(string strText) { UnityEngine.Profiling.Profiler.BeginSample("InlineText Parse ParseUnderlineTag"); mTextBuilder.Length = 0; if (string.IsNullOrEmpty(strText) || strText.IndexOf("<u>") == -1 || strText.IndexOf("</u>") == -1) { for (int i = 0; i < mUnderlineTagInfos.Count; ++i) { mUnderlineTagInfos[i].Reset(); } return(strText); } var indexText = 0; int index = 0; foreach (Match match in mUnderlineRegex.Matches(strText)) { mTextBuilder.Append(strText.Substring(indexText, match.Index - indexText)); if (index + 1 > mUnderlineTagInfos.Count) { var temp = new UnderlineTagInfo(); mUnderlineTagInfos.Add(temp); } //文本起始顶点索引 TODO 位置计算容易出问题,万一中间带有其他解释符号。所以下滑先只能放在次里面(仅次于超链接) mUnderlineTagInfos[index].StartIndex = mTextBuilder.Length; mUnderlineTagInfos[index].EndIndex = mTextBuilder.Length + match.Groups[1].Length; mTextBuilder.Append(match.Groups[1].Value); indexText = match.Index + match.Length; index++; } if (index < mUnderlineTagInfos.Count) { int count = mUnderlineTagInfos.Count; for (int i = index; i < count; ++i) { mUnderlineTagInfos[i].Reset(); } } mTextBuilder.Append(strText.Substring(indexText, strText.Length - indexText)); UnityEngine.Profiling.Profiler.EndSample(); return(mTextBuilder.ToString()); }
private void UnderlineTagsHandler() { if (mUnderlineTagInfos == null || mUnderlineTagInfos.Count == 0) { return; } for (int i = 0; i < mUnderlineTagInfos.Count; ++i) { UnderlineTagInfo temp = mUnderlineTagInfos[i]; if (!temp.IsValid()) { continue; } int vertexStart = mUnderlineTagInfos[i].StartIndex * 4; int vertexEnd = (mUnderlineTagInfos[i].EndIndex - 1) * 4 + 3; mUnderlineTagInfos[i].Boxes = GetBounds(vertexStart, vertexEnd); } TextGenerator textGenerator = new TextGenerator(); textGenerator.Populate("_", TextGenerationSettings); IList <UIVertex> underlineVerts = textGenerator.verts; for (int m = 0; m < mUnderlineTagInfos.Count; ++m) { var underlineInfo = mUnderlineTagInfos[m]; if (!underlineInfo.IsValid()) { continue; } if (underlineInfo.StartIndex >= mVertexHelperRef.currentVertCount) { continue; } for (int i = 0; i < underlineInfo.Boxes.Count; i++) { Vector3 startBoxPos = new Vector3(underlineInfo.Boxes[i].x, underlineInfo.Boxes[i].y, 0.0f); Vector3 endBoxPos = startBoxPos + new Vector3(underlineInfo.Boxes[i].width, 0.0f, 0.0f); AddUnderlineQuad(underlineVerts, startBoxPos, endBoxPos); } } }