public static int FindIntersectingLink(TextMeshPro text, Vector3 position, Camera camera)
        {
            Transform transform = text.transform;

            ScreenPointToWorldPointInRectangle(transform, position, camera, out position);
            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo tMP_LinkInfo = text.textInfo.linkInfo[i];
                bool         flag         = false;
                Vector3      a            = Vector3.zero;
                Vector3      b            = Vector3.zero;
                Vector3      zero         = Vector3.zero;
                Vector3      zero2        = Vector3.zero;
                for (int j = 0; j < tMP_LinkInfo.characterCount; j++)
                {
                    int num = tMP_LinkInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num];
                    int lineNumber = tMP_CharacterInfo.lineNumber;
                    if (!flag)
                    {
                        flag = true;
                        a    = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.bottomLine, 0f));
                        b    = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topLine, 0f));
                        if (tMP_LinkInfo.characterCount == 1)
                        {
                            flag  = false;
                            zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                            zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                            if (PointIntersectRectangle(position, a, b, zero2, zero))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_LinkInfo.characterCount - 1)
                    {
                        flag  = false;
                        zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num + 1].lineNumber)
                    {
                        flag  = false;
                        zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                }
            }
            return(-1);
        }
예제 #2
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character Selection
                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
                if (charIndex != -1 && charIndex != m_lastCharIndex)
                {
                    m_lastCharIndex = charIndex;

                    // Send event to any event listeners.
                    SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                }
                #endregion


                #region Example of Word Selection
                // Check if Mouse intersects any words and if so assign a random color to that word.
                int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
                if (wordIndex != -1 && wordIndex != m_lastWordIndex)
                {
                    m_lastWordIndex = wordIndex;

                    // Get the information about the selected word.
                    TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];

                    // Send the event to any listeners.
                    SendOnWordSelection(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
                }
                #endregion


                #region Example of Link Handling
                // Check if mouse intersects with any links.
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);

                // Handle new Link selection.
                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    // Get information about the link.
                    TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];

                    // Send the event to any listeners.
                    SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }
                #endregion
            }
        }
예제 #3
0
 // Token: 0x0600456E RID: 17774 RVA: 0x00174B44 File Offset: 0x00172F44
 private void LateUpdate()
 {
     if (TMP_TextUtilities.IsIntersectingRectTransform(this.m_TextComponent.rectTransform, Input.mousePosition, this.m_Camera))
     {
         int num = TMP_TextUtilities.FindIntersectingCharacter(this.m_TextComponent, Input.mousePosition, this.m_Camera, true);
         if (num != -1 && num != this.m_lastCharIndex)
         {
             this.m_lastCharIndex = num;
             this.SendOnCharacterSelection(this.m_TextComponent.textInfo.characterInfo[num].character, num);
         }
         int num2 = TMP_TextUtilities.FindIntersectingWord(this.m_TextComponent, Input.mousePosition, this.m_Camera);
         if (num2 != -1 && num2 != this.m_lastWordIndex)
         {
             this.m_lastWordIndex = num2;
             TMP_WordInfo tmp_WordInfo = this.m_TextComponent.textInfo.wordInfo[num2];
             this.SendOnWordSelection(tmp_WordInfo.GetWord(), tmp_WordInfo.firstCharacterIndex, tmp_WordInfo.characterCount);
         }
         int num3 = TMP_TextUtilities.FindIntersectingLine(this.m_TextComponent, Input.mousePosition, this.m_Camera);
         if (num3 != -1 && num3 != this.m_lastLineIndex)
         {
             this.m_lastLineIndex = num3;
             TMP_LineInfo tmp_LineInfo = this.m_TextComponent.textInfo.lineInfo[num3];
             char[]       array        = new char[tmp_LineInfo.characterCount];
             int          num4         = 0;
             while (num4 < tmp_LineInfo.characterCount && num4 < this.m_TextComponent.textInfo.characterInfo.Length)
             {
                 array[num4] = this.m_TextComponent.textInfo.characterInfo[num4 + tmp_LineInfo.firstCharacterIndex].character;
                 num4++;
             }
             string line = new string(array);
             this.SendOnLineSelection(line, tmp_LineInfo.firstCharacterIndex, tmp_LineInfo.characterCount);
         }
         int num5 = TMP_TextUtilities.FindIntersectingLink(this.m_TextComponent, Input.mousePosition, this.m_Camera);
         if (num5 != -1 && num5 != this.m_selectedLink)
         {
             this.m_selectedLink = num5;
             TMP_LinkInfo tmp_LinkInfo = this.m_TextComponent.textInfo.linkInfo[num5];
             this.SendOnLinkSelection(tmp_LinkInfo.GetLinkID(), tmp_LinkInfo.GetLinkText(), num5);
         }
     }
 }
예제 #4
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character or Sprite Selection

                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
                if (charIndex != -1 && charIndex != m_lastCharIndex)
                {
                    m_lastCharIndex = charIndex;

                    TMP_TextElementType elementType = m_TextComponent.textInfo.characterInfo[charIndex].elementType;

                    // Send event to any event listeners depending on whether it is a character or sprite.
                    if (elementType == TMP_TextElementType.Character)
                    {
                        SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                    else if (elementType == TMP_TextElementType.Sprite)
                    {
                        SendOnSpriteSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                }

                #endregion

                #region Example of Word Selection

                // Check if Mouse intersects any words and if so assign a random color to that word.
                int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
                if (wordIndex != -1 && wordIndex != m_lastWordIndex)
                {
                    m_lastWordIndex = wordIndex;

                    // Get the information about the selected word.
                    TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];

                    // Send the event to any listeners.
                    SendOnWordSelection(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
                }

                #endregion

                #region Example of Line Selection

                // Check if Mouse intersects any words and if so assign a random color to that word.
                int lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, Input.mousePosition, m_Camera);
                if (lineIndex != -1 && lineIndex != m_lastLineIndex)
                {
                    m_lastLineIndex = lineIndex;

                    // Get the information about the selected word.
                    TMP_LineInfo lineInfo = m_TextComponent.textInfo.lineInfo[lineIndex];

                    // Send the event to any listeners.
                    char[] buffer = new char[lineInfo.characterCount];
                    for (int i = 0; i < lineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
                    {
                        buffer[i] = m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
                    }

                    string lineText = new string(buffer);
                    SendOnLineSelection(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
                }

                #endregion

                #region Example of Link Handling

                // Check if mouse intersects with any links.
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);

                // Handle new Link selection.
                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    // Get information about the link.
                    TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];

                    // Send the event to any listeners.
                    SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }

                #endregion
            }
        }
예제 #5
0
        public static int FindNearestLink(TMP_Text text, Vector3 position, Camera camera)
        {
            RectTransform rectTransform = text.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            float num    = float.PositiveInfinity;
            int   result = 0;

            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo tMP_LinkInfo = text.textInfo.linkInfo[i];
                bool         flag         = false;
                Vector3      vector       = Vector3.zero;
                Vector3      vector2      = Vector3.zero;
                Vector3      zero         = Vector3.zero;
                Vector3      zero2        = Vector3.zero;
                for (int j = 0; j < tMP_LinkInfo.linkTextLength; j++)
                {
                    int num2 = tMP_LinkInfo.linkTextfirstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num2];
                    int lineNumber = tMP_CharacterInfo.lineNumber;
                    if (text.overflowMode == TextOverflowModes.Page && tMP_CharacterInfo.pageNumber + 1 != text.pageToDisplay)
                    {
                        continue;
                    }
                    if (!flag)
                    {
                        flag    = true;
                        vector  = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.descender, 0f));
                        vector2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.ascender, 0f));
                        if (tMP_LinkInfo.linkTextLength == 1)
                        {
                            flag  = false;
                            zero  = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                            zero2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                            if (PointIntersectRectangle(position, vector, vector2, zero2, zero))
                            {
                                return(i);
                            }
                            float num3 = DistanceToLine(vector, vector2, position);
                            float num4 = DistanceToLine(vector2, zero2, position);
                            float num5 = DistanceToLine(zero2, zero, position);
                            float num6 = DistanceToLine(zero, vector, position);
                            float num7 = (num3 < num4) ? num3 : num4;
                            num7 = ((num7 < num5) ? num7 : num5);
                            num7 = ((num7 < num6) ? num7 : num6);
                            if (num > num7)
                            {
                                num    = num7;
                                result = i;
                            }
                        }
                    }
                    if (flag && j == tMP_LinkInfo.linkTextLength - 1)
                    {
                        flag  = false;
                        zero  = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                        zero2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                        if (PointIntersectRectangle(position, vector, vector2, zero2, zero))
                        {
                            return(i);
                        }
                        float num8  = DistanceToLine(vector, vector2, position);
                        float num9  = DistanceToLine(vector2, zero2, position);
                        float num10 = DistanceToLine(zero2, zero, position);
                        float num11 = DistanceToLine(zero, vector, position);
                        float num12 = (num8 < num9) ? num8 : num9;
                        num12 = ((num12 < num10) ? num12 : num10);
                        num12 = ((num12 < num11) ? num12 : num11);
                        if (num > num12)
                        {
                            num    = num12;
                            result = i;
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num2 + 1].lineNumber)
                    {
                        flag  = false;
                        zero  = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                        zero2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                        if (PointIntersectRectangle(position, vector, vector2, zero2, zero))
                        {
                            return(i);
                        }
                        float num13 = DistanceToLine(vector, vector2, position);
                        float num14 = DistanceToLine(vector2, zero2, position);
                        float num15 = DistanceToLine(zero2, zero, position);
                        float num16 = DistanceToLine(zero, vector, position);
                        float num17 = (num13 < num14) ? num13 : num14;
                        num17 = ((num17 < num15) ? num17 : num15);
                        num17 = ((num17 < num16) ? num17 : num16);
                        if (num > num17)
                        {
                            num    = num17;
                            result = i;
                        }
                    }
                }
            }
            return(result);
        }
예제 #6
0
        public static int FindIntersectingLink(TMP_Text text, Vector3 position, Camera camera)
        {
            Transform transform = text.transform;

            ScreenPointToWorldPointInRectangle(transform, position, camera, out position);
            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo tMP_LinkInfo = text.textInfo.linkInfo[i];
                bool         flag         = false;
                Vector3      a            = Vector3.zero;
                Vector3      b            = Vector3.zero;
                Vector3      zero         = Vector3.zero;
                Vector3      zero2        = Vector3.zero;
                for (int j = 0; j < tMP_LinkInfo.linkTextLength; j++)
                {
                    int num = tMP_LinkInfo.linkTextfirstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num];
                    int lineNumber = tMP_CharacterInfo.lineNumber;
                    if (text.overflowMode == TextOverflowModes.Page && tMP_CharacterInfo.pageNumber + 1 != text.pageToDisplay)
                    {
                        continue;
                    }
                    if (!flag)
                    {
                        flag = true;
                        a    = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.descender, 0f));
                        b    = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.ascender, 0f));
                        if (tMP_LinkInfo.linkTextLength == 1)
                        {
                            flag  = false;
                            zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                            zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                            if (PointIntersectRectangle(position, a, b, zero2, zero))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_LinkInfo.linkTextLength - 1)
                    {
                        flag  = false;
                        zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                        zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num + 1].lineNumber)
                    {
                        flag  = false;
                        zero  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f));
                        zero2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                }
            }
            return(-1);
        }
예제 #7
0
    public bool TestForHit(Vector2 screenPoint, Camera eventCamera, Action<string, int> block)
    {
        TMP_TextInfo textInfo = null;
        TMP_Text text = null;

        if (entity.text != null) {
            text = entity.text;
            textInfo = entity.text.textInfo;
        }
        if (entity.textGUI != null) {
            text = entity.textGUI;
            textInfo = entity.textGUI.textInfo;
        }

        if (textInfo != null) {

            // find the closest link to our touch point
            float minDistance = 999999;
            TMP_LinkInfo minLinkInfo = new TMP_LinkInfo ();

            Transform rectTransform = text.transform;
            Vector3 position = screenPoint;

            // Convert position into Worldspace coordinates
            TMP_TextUtilities.ScreenPointToWorldPointInRectangle (rectTransform, position, eventCamera, out position);

            for (int i = 0; i < text.textInfo.linkCount; i++) {
                TMP_LinkInfo linkInfo = text.textInfo.linkInfo [i];

                bool isBeginRegion = false;

                Vector3 bl = Vector3.zero;
                Vector3 tl = Vector3.zero;
                Vector3 br = Vector3.zero;
                Vector3 tr = Vector3.zero;

                // Iterate through each character of the word
                for (int j = 0; j < linkInfo.linkTextLength; j++) {
                    int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
                    TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo [characterIndex];
                    int currentLine = currentCharInfo.lineNumber;

                    // Check if Link characters are on the current page
                    if (text.OverflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != text.pageToDisplay)
                        continue;

                    if (isBeginRegion == false) {
                        isBeginRegion = true;

                        bl = rectTransform.TransformPoint (new Vector3 (currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0));
                        tl = rectTransform.TransformPoint (new Vector3 (currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0));

                        // If Word is one character
                        if (linkInfo.linkTextLength == 1) {
                            isBeginRegion = false;

                            br = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                            tr = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                            // Check for Intersection
                            IsCloserToPoint (position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint (position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint (position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint (position, br, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint (position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                        }
                    }

                    // Last Character of Word
                    if (isBeginRegion && j == linkInfo.linkTextLength - 1) {
                        isBeginRegion = false;

                        br = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                        tr = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                        IsCloserToPoint (position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, br, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                    }
                    // If Word is split on more than one line.
                    else if (isBeginRegion && currentLine != text.textInfo.characterInfo [characterIndex + 1].lineNumber) {
                        isBeginRegion = false;

                        br = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                        tr = rectTransform.TransformPoint (new Vector3 (currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                        IsCloserToPoint (position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, br, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint (position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                    }
                }
            }

            int linkIdx = Array.IndexOf (text.textInfo.linkInfo, minLinkInfo);
            if (linkIdx >= 0) {
                if (block != null) {
                    block (minLinkInfo.GetLinkText (), linkIdx);
                }
                return true;
            }
        }

        return false;
    }
예제 #8
0
 private void IsCloserToPoint(Vector3 mousePoint, Vector3 testPoint, TMP_LinkInfo testLink, ref float minDistance, ref TMP_LinkInfo minLinkInfo)
 {
     float testDistance = Vector3.SqrMagnitude (mousePoint - testPoint);
     if (testDistance < minDistance) {
         minDistance = testDistance;
         minLinkInfo = testLink;
     }
 }
        public static int FindNearestLink(TextMeshPro text, Vector3 position, Camera camera)
        {
            Transform transform = text.transform;

            ScreenPointToWorldPointInRectangle(transform, position, camera, out position);
            float num    = float.PositiveInfinity;
            int   result = 0;

            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo tMP_LinkInfo = text.textInfo.linkInfo[i];
                bool         flag         = false;
                Vector3      vector       = Vector3.zero;
                Vector3      vector2      = Vector3.zero;
                Vector3      vector3      = Vector3.zero;
                Vector3      vector4      = Vector3.zero;
                for (int j = 0; j < tMP_LinkInfo.characterCount; j++)
                {
                    int num2 = tMP_LinkInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num2];
                    int lineNumber = tMP_CharacterInfo.lineNumber;
                    if (!flag)
                    {
                        flag    = true;
                        vector  = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector2 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topLine, 0f));
                        if (tMP_LinkInfo.characterCount == 1)
                        {
                            flag    = false;
                            vector3 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                            vector4 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                            if (PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_LinkInfo.characterCount - 1)
                    {
                        flag    = false;
                        vector3 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector4 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                        if (PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                        {
                            return(i);
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num2 + 1].lineNumber)
                    {
                        flag    = false;
                        vector3 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector4 = transform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                        if (PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                        {
                            return(i);
                        }
                    }
                }
                float num3 = DistanceToLine(vector, vector2, position);
                float num4 = DistanceToLine(vector2, vector4, position);
                float num5 = DistanceToLine(vector4, vector3, position);
                float num6 = DistanceToLine(vector3, vector, position);
                float num7 = (!(num3 < num4)) ? num4 : num3;
                num7 = ((!(num7 < num5)) ? num5 : num7);
                num7 = ((!(num7 < num6)) ? num6 : num7);
                if (num > num7)
                {
                    num    = num7;
                    result = i;
                }
            }
            return(result);
        }
예제 #10
0
        public static int FindNearestLink(TMP_Text text, Vector3 position, Camera camera)
        {
            RectTransform rectTransform = text.rectTransform;

            TMP_TextUtilities.ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            float num    = float.PositiveInfinity;
            int   result = 0;

            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo tmp_LinkInfo = text.textInfo.linkInfo[i];
                bool         flag         = false;
                Vector3      vector       = Vector3.zero;
                Vector3      vector2      = Vector3.zero;
                Vector3      vector3      = Vector3.zero;
                Vector3      vector4      = Vector3.zero;
                for (int j = 0; j < tmp_LinkInfo.linkTextLength; j++)
                {
                    int num2 = tmp_LinkInfo.linkTextfirstCharacterIndex + j;
                    TMP_CharacterInfo tmp_CharacterInfo = text.textInfo.characterInfo[num2];
                    int lineNumber = tmp_CharacterInfo.lineNumber;
                    if (text.overflowMode != TextOverflowModes.Page || tmp_CharacterInfo.pageNumber + 1 == text.pageToDisplay)
                    {
                        if (!flag)
                        {
                            flag    = true;
                            vector  = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.bottomLeft.x, tmp_CharacterInfo.descender, 0f));
                            vector2 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.bottomLeft.x, tmp_CharacterInfo.ascender, 0f));
                            if (tmp_LinkInfo.linkTextLength == 1)
                            {
                                flag    = false;
                                vector3 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.descender, 0f));
                                vector4 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.ascender, 0f));
                                if (TMP_TextUtilities.PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                                {
                                    return(i);
                                }
                                float num3 = TMP_TextUtilities.DistanceToLine(vector, vector2, position);
                                float num4 = TMP_TextUtilities.DistanceToLine(vector2, vector4, position);
                                float num5 = TMP_TextUtilities.DistanceToLine(vector4, vector3, position);
                                float num6 = TMP_TextUtilities.DistanceToLine(vector3, vector, position);
                                float num7 = (num3 >= num4) ? num4 : num3;
                                num7 = ((num7 >= num5) ? num5 : num7);
                                num7 = ((num7 >= num6) ? num6 : num7);
                                if (num > num7)
                                {
                                    num    = num7;
                                    result = i;
                                }
                            }
                        }
                        if (flag && j == tmp_LinkInfo.linkTextLength - 1)
                        {
                            flag    = false;
                            vector3 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.descender, 0f));
                            vector4 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.ascender, 0f));
                            if (TMP_TextUtilities.PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                            {
                                return(i);
                            }
                            float num8  = TMP_TextUtilities.DistanceToLine(vector, vector2, position);
                            float num9  = TMP_TextUtilities.DistanceToLine(vector2, vector4, position);
                            float num10 = TMP_TextUtilities.DistanceToLine(vector4, vector3, position);
                            float num11 = TMP_TextUtilities.DistanceToLine(vector3, vector, position);
                            float num12 = (num8 >= num9) ? num9 : num8;
                            num12 = ((num12 >= num10) ? num10 : num12);
                            num12 = ((num12 >= num11) ? num11 : num12);
                            if (num > num12)
                            {
                                num    = num12;
                                result = i;
                            }
                        }
                        else if (flag && lineNumber != text.textInfo.characterInfo[num2 + 1].lineNumber)
                        {
                            flag    = false;
                            vector3 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.descender, 0f));
                            vector4 = rectTransform.TransformPoint(new Vector3(tmp_CharacterInfo.topRight.x, tmp_CharacterInfo.ascender, 0f));
                            if (TMP_TextUtilities.PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                            {
                                return(i);
                            }
                            float num13 = TMP_TextUtilities.DistanceToLine(vector, vector2, position);
                            float num14 = TMP_TextUtilities.DistanceToLine(vector2, vector4, position);
                            float num15 = TMP_TextUtilities.DistanceToLine(vector4, vector3, position);
                            float num16 = TMP_TextUtilities.DistanceToLine(vector3, vector, position);
                            float num17 = (num13 >= num14) ? num14 : num13;
                            num17 = ((num17 >= num15) ? num15 : num17);
                            num17 = ((num17 >= num16) ? num16 : num17);
                            if (num > num17)
                            {
                                num    = num17;
                                result = i;
                            }
                        }
                    }
                }
            }
            return(result);
        }