Exemple #1
0
    //计算在顶点中起始和结束位置,考虑<u></u>的影响,其他标签暂且不考虑
    //归根到底是计算文字在顶点数据中位置方式不太靠谱
    protected string ParseHrefTags(string strText)
    {
        UnityEngine.Profiling.Profiler.BeginSample("InlineText Parse ParseUnderlineTag");

        mTextBuilder.Length = 0;

        if (string.IsNullOrEmpty(strText) || strText.IndexOf("href") == -1)
        {
            for (int i = 0; i < mHrefTagInfos.Count; ++i)
            {
                mHrefTagInfos[i].Reset();
            }
            return(strText);
        }

        var indexText = 0;
        int index     = 0;

        foreach (Match match in mHrefRegex.Matches(strText))
        {
            mTextBuilder.Append(strText.Substring(indexText, match.Index - indexText));

            if (index + 1 > mHrefTagInfos.Count)
            {
                var temp = new HrefTagInfo();
                mHrefTagInfos.Add(temp);
            }

            HrefTagInfo hrefInfo = mHrefTagInfos[index];

            hrefInfo.StartIndex = mTextBuilder.Length;
            hrefInfo.EndIndex   = mTextBuilder.Length + match.Groups[2].Length;
            hrefInfo.Name       = match.Groups[1].Value;

            mTextBuilder.Append(match.Groups[2].Value);
            indexText = match.Index + match.Length;
            index++;
        }
        mTextBuilder.Append(strText.Substring(indexText, strText.Length - indexText));

        if (index < mHrefTagInfos.Count)
        {
            int count = mHrefTagInfos.Count;
            for (int i = index; i < count; ++i)
            {
                mHrefTagInfos[i].Reset();
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();

        return(mTextBuilder.ToString());
    }
Exemple #2
0
    private void HerfTagHandler()
    {
        if (mHrefTagInfos == null || mHrefTagInfos.Count == 0)
        {
            return;
        }

        for (int i = 0; i < mHrefTagInfos.Count; ++i)
        {
            HrefTagInfo temp = mHrefTagInfos[i];
            if (!temp.IsValid())
            {
                continue;
            }

            int vertexStart = temp.StartIndex * 4;
            int vertexEnd   = (temp.EndIndex - 1) * 4 + 3;

            mHrefTagInfos[i].Boxes = GetBounds(vertexStart, vertexEnd);
        }
    }