Пример #1
0
        public static int GetCursorIndexFromPosition(TMP_Text textComponent, Vector3 position, Camera camera, out CaretPosition cursor)
        {
            int num  = FindNearestLine(textComponent, position, camera);
            int num2 = FindNearestCharacterOnLine(textComponent, position, num, camera, false);

            if (textComponent.textInfo.lineInfo[num].characterCount == 1)
            {
                cursor = CaretPosition.Left;
                return(num2);
            }
            RectTransform rectTransform = textComponent.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            TMP_CharacterInfo tMP_CharacterInfo = textComponent.textInfo.characterInfo[num2];
            Vector3           vector            = rectTransform.TransformPoint(tMP_CharacterInfo.bottomLeft);
            Vector3           vector2           = rectTransform.TransformPoint(tMP_CharacterInfo.topRight);
            float             num3 = (position.x - vector.x) / (vector2.x - vector.x);

            if (num3 < 0.5f)
            {
                cursor = CaretPosition.Left;
                return(num2);
            }
            cursor = CaretPosition.Right;
            return(num2);
        }
        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);
        }
Пример #3
0
        private IEnumerator DoSpriteAnimationInternal(int currentCharacter, TMP_SpriteAsset spriteAsset, int start, int end, int framerate)
        {
            if ((Object)(object)m_TextComponent == null)
            {
                yield break;
            }
            yield return(null);

            int currentFrame = start;

            if (end > spriteAsset.spriteInfoList.Count)
            {
                end = spriteAsset.spriteInfoList.Count - 1;
            }
            TMP_CharacterInfo charInfo = m_TextComponent.textInfo.characterInfo[currentCharacter];
            int          materialIndex = charInfo.materialReferenceIndex;
            int          vertexIndex   = charInfo.vertexIndex;
            TMP_MeshInfo meshInfo      = m_TextComponent.textInfo.meshInfo[materialIndex];
            float        elapsedTime   = 0f;
            float        targetTime    = 1f / (float)Mathf.Abs(framerate);

            while (true)
            {
                if (elapsedTime > targetTime)
                {
                    elapsedTime = 0f;
                    TMP_Sprite sprite      = spriteAsset.spriteInfoList[currentFrame];
                    Vector3[]  vertices    = meshInfo.vertices;
                    Vector2    origin      = new Vector2(charInfo.origin, charInfo.baseLine);
                    float      spriteScale = charInfo.fontAsset.fontInfo.Ascender / sprite.height * sprite.scale * charInfo.scale;
                    Vector3    bl          = new Vector3(origin.x + sprite.xOffset * spriteScale, origin.y + (sprite.yOffset - sprite.height) * spriteScale);
                    Vector3    tl          = new Vector3(bl.x, origin.y + sprite.yOffset * spriteScale);
                    Vector3    tr          = new Vector3(origin.x + (sprite.xOffset + sprite.width) * spriteScale, tl.y);
                    Vector3    br          = new Vector3(tr.x, bl.y);
                    vertices[vertexIndex]     = bl;
                    vertices[vertexIndex + 1] = tl;
                    vertices[vertexIndex + 2] = tr;
                    vertices[vertexIndex + 3] = br;
                    Vector2[] uvs0 = meshInfo.uvs0;
                    Vector2   uv0  = new Vector2(sprite.x / (float)spriteAsset.spriteSheet.width, sprite.y / (float)spriteAsset.spriteSheet.height);
                    Vector2   uv1  = new Vector2(uv0.x, (sprite.y + sprite.height) / (float)spriteAsset.spriteSheet.height);
                    Vector2   uv2  = new Vector2((sprite.x + sprite.width) / (float)spriteAsset.spriteSheet.width, uv1.y);
                    Vector2   uv3  = new Vector2(uv2.x, uv0.y);
                    uvs0[vertexIndex]      = uv0;
                    uvs0[vertexIndex + 1]  = uv1;
                    uvs0[vertexIndex + 2]  = uv2;
                    uvs0[vertexIndex + 3]  = uv3;
                    meshInfo.mesh.vertices = vertices;
                    meshInfo.mesh.uv       = uvs0;
                    m_TextComponent.UpdateGeometry(meshInfo.mesh, materialIndex);
                    currentFrame = ((framerate > 0) ? ((currentFrame >= end) ? start : (currentFrame + 1)) : ((currentFrame <= start) ? end : (currentFrame - 1)));
                }
                elapsedTime += Time.deltaTime;
                yield return(null);
            }
        }
        private IEnumerator DoSpriteAnimationInternal(int currentCharacter, TMP_SpriteAsset spriteAsset, int start, int end, int framerate)
        {
            if (m_TextComponent == null)
            {
                yield break;
            }
            yield return(null);

            int currentFrame = start;

            if (end > spriteAsset.spriteInfoList.Count)
            {
                end = spriteAsset.spriteInfoList.Count - 1;
            }
            TMP_CharacterInfo charInfo = m_TextComponent.textInfo.characterInfo[currentCharacter];
            int          materialIndex = charInfo.materialReferenceIndex;
            int          vertexIndex   = charInfo.vertexIndex;
            TMP_MeshInfo meshInfo      = m_TextComponent.textInfo.meshInfo[materialIndex];
            float        elapsedTime   = 0f;
            float        targetTime    = 1f / (float)Mathf.Abs(framerate);

            while (true)
            {
                if (elapsedTime > targetTime)
                {
                    elapsedTime = 0f;
                    TMP_Sprite tMP_Sprite = spriteAsset.spriteInfoList[currentFrame];
                    Vector3[]  vertices   = meshInfo.vertices;
                    Vector2    vector     = new Vector2(charInfo.origin, charInfo.baseLine);
                    float      num        = charInfo.fontAsset.fontInfo.Ascender / tMP_Sprite.height * tMP_Sprite.scale * charInfo.scale;
                    Vector3    vector2    = new Vector3(vector.x + tMP_Sprite.xOffset * num, vector.y + (tMP_Sprite.yOffset - tMP_Sprite.height) * num);
                    Vector3    vector3    = new Vector3(vector2.x, vector.y + tMP_Sprite.yOffset * num);
                    Vector3    vector4    = new Vector3(vector.x + (tMP_Sprite.xOffset + tMP_Sprite.width) * num, vector3.y);
                    Vector3    vector5    = new Vector3(vector4.x, vector2.y);
                    vertices[vertexIndex]     = vector2;
                    vertices[vertexIndex + 1] = vector3;
                    vertices[vertexIndex + 2] = vector4;
                    vertices[vertexIndex + 3] = vector5;
                    Vector2[] uvs     = meshInfo.uvs0;
                    Vector2   vector6 = new Vector2(tMP_Sprite.x / (float)spriteAsset.spriteSheet.width, tMP_Sprite.y / (float)spriteAsset.spriteSheet.height);
                    Vector2   vector7 = new Vector2(vector6.x, (tMP_Sprite.y + tMP_Sprite.height) / (float)spriteAsset.spriteSheet.height);
                    Vector2   vector8 = new Vector2((tMP_Sprite.x + tMP_Sprite.width) / (float)spriteAsset.spriteSheet.width, vector7.y);
                    Vector2   vector9 = new Vector2(vector8.x, vector6.y);
                    uvs[vertexIndex]       = vector6;
                    uvs[vertexIndex + 1]   = vector7;
                    uvs[vertexIndex + 2]   = vector8;
                    uvs[vertexIndex + 3]   = vector9;
                    meshInfo.mesh.vertices = vertices;
                    meshInfo.mesh.uv       = uvs;
                    m_TextComponent.UpdateGeometry(meshInfo.mesh, materialIndex);
                    currentFrame = ((framerate > 0) ? ((currentFrame >= end) ? start : (currentFrame + 1)) : ((currentFrame <= start) ? end : (currentFrame - 1)));
                }
                elapsedTime += Time.deltaTime;
                yield return(null);
            }
        }
Пример #5
0
        public static int GetCursorIndexFromPosition(TMP_Text textComponent, Vector3 position, Camera camera)
        {
            int           num           = FindNearestCharacter(textComponent, position, camera, false);
            RectTransform rectTransform = textComponent.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            TMP_CharacterInfo tMP_CharacterInfo = textComponent.textInfo.characterInfo[num];
            Vector3           vector            = rectTransform.TransformPoint(tMP_CharacterInfo.bottomLeft);
            Vector3           vector2           = rectTransform.TransformPoint(tMP_CharacterInfo.topRight);
            float             num2 = (position.x - vector.x) / (vector2.x - vector.x);

            if (num2 < 0.5f)
            {
                return(num);
            }
            return(num + 1);
        }
Пример #6
0
        public static int FindNearestCharacterOnLine(TMP_Text text, Vector3 position, int line, Camera camera, bool visibleOnly)
        {
            RectTransform rectTransform = text.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            int   firstCharacterIndex = text.textInfo.lineInfo[line].firstCharacterIndex;
            int   lastCharacterIndex  = text.textInfo.lineInfo[line].lastCharacterIndex;
            float num    = float.PositiveInfinity;
            int   result = lastCharacterIndex;

            for (int i = firstCharacterIndex; i < lastCharacterIndex; i++)
            {
                TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[i];
                if (!visibleOnly || tMP_CharacterInfo.isVisible)
                {
                    Vector3 vector  = rectTransform.TransformPoint(tMP_CharacterInfo.bottomLeft);
                    Vector3 vector2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topRight.y, 0f));
                    Vector3 vector3 = rectTransform.TransformPoint(tMP_CharacterInfo.topRight);
                    Vector3 vector4 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLeft.y, 0f));
                    if (PointIntersectRectangle(position, vector, vector2, vector3, vector4))
                    {
                        result = i;
                        break;
                    }
                    float num2 = DistanceToLine(vector, vector2, position);
                    float num3 = DistanceToLine(vector2, vector3, position);
                    float num4 = DistanceToLine(vector3, vector4, position);
                    float num5 = DistanceToLine(vector4, vector, position);
                    float num6 = (num2 < num3) ? num2 : num3;
                    num6 = ((num6 < num4) ? num6 : num4);
                    num6 = ((num6 < num5) ? num6 : num5);
                    if (num > num6)
                    {
                        num    = num6;
                        result = i;
                    }
                }
            }
            return(result);
        }
Пример #7
0
        public static int FindIntersectingCharacter(TMP_Text text, Vector3 position, Camera camera, bool visibleOnly)
        {
            RectTransform rectTransform = text.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            for (int i = 0; i < text.textInfo.characterCount; i++)
            {
                TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[i];
                if (!visibleOnly || tMP_CharacterInfo.isVisible)
                {
                    Vector3 a = rectTransform.TransformPoint(tMP_CharacterInfo.bottomLeft);
                    Vector3 b = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topRight.y, 0f));
                    Vector3 c = rectTransform.TransformPoint(tMP_CharacterInfo.topRight);
                    Vector3 d = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLeft.y, 0f));
                    if (PointIntersectRectangle(position, a, b, c, d))
                    {
                        return(i);
                    }
                }
            }
            return(-1);
        }
Пример #8
0
        public static int FindNearestCharacter(TMP_Text text, Vector3 position, Camera camera, bool visibleOnly)
        {
            RectTransform rectTransform = text.rectTransform;
            float         num           = float.PositiveInfinity;
            int           result        = 0;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            for (int i = 0; i < text.textInfo.characterCount; i++)
            {
                TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[i];
                if (!visibleOnly || tMP_CharacterInfo.isVisible)
                {
                    Vector3 vector  = rectTransform.TransformPoint(tMP_CharacterInfo.bottomLeft);
                    Vector3 vector2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topRight.y, 0f));
                    Vector3 vector3 = rectTransform.TransformPoint(tMP_CharacterInfo.topRight);
                    Vector3 vector4 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLeft.y, 0f));
                    if (PointIntersectRectangle(position, vector, vector2, vector3, vector4))
                    {
                        return(i);
                    }
                    float num2 = DistanceToLine(vector, vector2, position);
                    float num3 = DistanceToLine(vector2, vector3, position);
                    float num4 = DistanceToLine(vector3, vector4, position);
                    float num5 = DistanceToLine(vector4, vector, position);
                    float num6 = (!(num2 < num3)) ? num3 : num2;
                    num6 = ((!(num6 < num4)) ? num4 : num6);
                    num6 = ((!(num6 < num5)) ? num5 : num6);
                    if (num > num6)
                    {
                        num    = num6;
                        result = i;
                    }
                }
            }
            return(result);
        }
Пример #9
0
        public static int FindIntersectingWord(TMP_Text text, Vector3 position, Camera camera)
        {
            RectTransform rectTransform = text.rectTransform;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            for (int i = 0; i < text.textInfo.wordCount; i++)
            {
                TMP_WordInfo tMP_WordInfo = text.textInfo.wordInfo[i];
                bool         flag         = false;
                Vector3      a            = Vector3.zero;
                Vector3      b            = Vector3.zero;
                Vector3      zero         = Vector3.zero;
                Vector3      zero2        = Vector3.zero;
                float        num          = float.NegativeInfinity;
                float        num2         = float.PositiveInfinity;
                for (int j = 0; j < tMP_WordInfo.characterCount; j++)
                {
                    int num3 = tMP_WordInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num3];
                    int  lineNumber = tMP_CharacterInfo.lineNumber;
                    bool isVisible  = tMP_CharacterInfo.isVisible;
                    num  = Mathf.Max(num, tMP_CharacterInfo.ascender);
                    num2 = Mathf.Min(num2, tMP_CharacterInfo.descender);
                    if (!flag && isVisible)
                    {
                        flag = true;
                        a    = new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.descender, 0f);
                        b    = new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.ascender, 0f);
                        if (tMP_WordInfo.characterCount == 1)
                        {
                            flag  = false;
                            zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f);
                            zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f);
                            a     = rectTransform.TransformPoint(new Vector3(a.x, num2, 0f));
                            b     = rectTransform.TransformPoint(new Vector3(b.x, num, 0f));
                            zero2 = rectTransform.TransformPoint(new Vector3(zero2.x, num, 0f));
                            zero  = rectTransform.TransformPoint(new Vector3(zero.x, num2, 0f));
                            if (PointIntersectRectangle(position, a, b, zero2, zero))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_WordInfo.characterCount - 1)
                    {
                        flag  = false;
                        zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f);
                        zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f);
                        a     = rectTransform.TransformPoint(new Vector3(a.x, num2, 0f));
                        b     = rectTransform.TransformPoint(new Vector3(b.x, num, 0f));
                        zero2 = rectTransform.TransformPoint(new Vector3(zero2.x, num, 0f));
                        zero  = rectTransform.TransformPoint(new Vector3(zero.x, num2, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num3 + 1].lineNumber)
                    {
                        flag  = false;
                        zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.descender, 0f);
                        zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.ascender, 0f);
                        a     = rectTransform.TransformPoint(new Vector3(a.x, num2, 0f));
                        b     = rectTransform.TransformPoint(new Vector3(b.x, num, 0f));
                        zero2 = rectTransform.TransformPoint(new Vector3(zero2.x, num, 0f));
                        zero  = rectTransform.TransformPoint(new Vector3(zero.x, num2, 0f));
                        num   = float.NegativeInfinity;
                        num2  = float.PositiveInfinity;
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                }
            }
            return(-1);
        }
Пример #10
0
        //public char[] word;
        //public string word;

        public string GetWord(TMP_CharacterInfo[] charInfo)
        {
            string word = string.Empty;
            
            for (int i = firstCharacterIndex; i < lastCharacterIndex + 1; i++)
            {
                word += charInfo[i].character;
            }

            return word;
        }
Пример #11
0
 // Used with Advanced Layout Component.
 void UpdateMeshData(TMP_CharacterInfo[] characterInfo, int characterCount, Mesh mesh, Vector3[] vertices, Vector2[] uv0s, Vector2[] uv2s, Color32[] vertexColors, Vector3[] normals, Vector4[] tangents)
 {
     m_textInfo.characterInfo = characterInfo;
     m_textInfo.characterCount = (short)characterCount;
     //m_meshInfo.mesh = mesh;
     //m_meshInfo.vertices = vertices;
     //m_meshInfo.uv0s = uv0s;
     //m_meshInfo.uv2s = uv2s;
     //m_meshInfo.vertexColors = m_vertColors;
     //m_meshInfo.normals = normals;
     //m_meshInfo.tangents = tangents;
 }
        public static int FindIntersectingWord(TextMeshPro text, Vector3 position, Camera camera)
        {
            Transform transform = text.transform;

            ScreenPointToWorldPointInRectangle(transform, position, camera, out position);
            for (int i = 0; i < text.textInfo.wordCount; i++)
            {
                TMP_WordInfo tMP_WordInfo = text.textInfo.wordInfo[i];
                bool         flag         = false;
                Vector3      a            = Vector3.zero;
                Vector3      b            = Vector3.zero;
                Vector3      zero         = Vector3.zero;
                Vector3      zero2        = Vector3.zero;
                float        num          = float.NegativeInfinity;
                float        num2         = float.PositiveInfinity;
                for (int j = 0; j < tMP_WordInfo.characterCount; j++)
                {
                    int num3 = tMP_WordInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num3];
                    int  lineNumber = tMP_CharacterInfo.lineNumber;
                    bool flag2      = (num3 <= text.maxVisibleCharacters && tMP_CharacterInfo.lineNumber <= text.maxVisibleLines && (text.OverflowMode != TextOverflowModes.Page || tMP_CharacterInfo.pageNumber + 1 == text.pageToDisplay)) ? true : false;
                    num  = Mathf.Max(num, tMP_CharacterInfo.topLine);
                    num2 = Mathf.Min(num2, tMP_CharacterInfo.bottomLine);
                    if (!flag && flag2)
                    {
                        flag = true;
                        a    = new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.bottomLine, 0f);
                        b    = new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topLine, 0f);
                        if (tMP_WordInfo.characterCount == 1)
                        {
                            flag  = false;
                            zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f);
                            zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f);
                            a     = transform.TransformPoint(new Vector3(a.x, num2, 0f));
                            b     = transform.TransformPoint(new Vector3(b.x, num, 0f));
                            zero2 = transform.TransformPoint(new Vector3(zero2.x, num, 0f));
                            zero  = transform.TransformPoint(new Vector3(zero.x, num2, 0f));
                            if (PointIntersectRectangle(position, a, b, zero2, zero))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_WordInfo.characterCount - 1)
                    {
                        flag  = false;
                        zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f);
                        zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f);
                        a     = transform.TransformPoint(new Vector3(a.x, num2, 0f));
                        b     = transform.TransformPoint(new Vector3(b.x, num, 0f));
                        zero2 = transform.TransformPoint(new Vector3(zero2.x, num, 0f));
                        zero  = transform.TransformPoint(new Vector3(zero.x, num2, 0f));
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                    else if (flag && lineNumber != text.textInfo.characterInfo[num3 + 1].lineNumber)
                    {
                        flag  = false;
                        zero  = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f);
                        zero2 = new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f);
                        a     = transform.TransformPoint(new Vector3(a.x, num2, 0f));
                        b     = transform.TransformPoint(new Vector3(b.x, num, 0f));
                        zero2 = transform.TransformPoint(new Vector3(zero2.x, num, 0f));
                        zero  = transform.TransformPoint(new Vector3(zero.x, num2, 0f));
                        num   = float.NegativeInfinity;
                        num2  = float.PositiveInfinity;
                        if (PointIntersectRectangle(position, a, b, zero2, zero))
                        {
                            return(i);
                        }
                    }
                }
            }
            return(-1);
        }
Пример #13
0
        public static int FindNearestWord(TMP_Text text, Vector3 position, Camera camera)
        {
            RectTransform rectTransform = text.rectTransform;
            float         num           = float.PositiveInfinity;
            int           result        = 0;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            for (int i = 0; i < text.textInfo.wordCount; i++)
            {
                TMP_WordInfo tMP_WordInfo = text.textInfo.wordInfo[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_WordInfo.characterCount; j++)
                {
                    int num2 = tMP_WordInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num2];
                    int  lineNumber = tMP_CharacterInfo.lineNumber;
                    bool isVisible  = tMP_CharacterInfo.isVisible;
                    if (!flag && isVisible)
                    {
                        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_WordInfo.characterCount == 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)) ? num4 : num3;
                            num7 = ((!(num7 < num5)) ? num5 : num7);
                            num7 = ((!(num7 < num6)) ? num6 : num7);
                            if (num > num7)
                            {
                                num    = num7;
                                result = i;
                            }
                        }
                    }
                    if (flag && j == tMP_WordInfo.characterCount - 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)) ? 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;
                        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)) ? num14 : num13;
                        num17 = ((!(num17 < num15)) ? num15 : num17);
                        num17 = ((!(num17 < num16)) ? num16 : num17);
                        if (num > num17)
                        {
                            num    = num17;
                            result = i;
                        }
                    }
                }
            }
            return(result);
        }
        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);
        }
        public static int FindNearestWord(TextMeshProUGUI text, Vector3 position, Camera camera)
        {
            RectTransform rectTransform = text.rectTransform;
            float         num           = float.PositiveInfinity;
            int           result        = 0;

            ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
            for (int i = 0; i < text.textInfo.wordCount; i++)
            {
                TMP_WordInfo tMP_WordInfo = text.textInfo.wordInfo[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_WordInfo.characterCount; j++)
                {
                    int num2 = tMP_WordInfo.firstCharacterIndex + j;
                    TMP_CharacterInfo tMP_CharacterInfo = text.textInfo.characterInfo[num2];
                    int  lineNumber = tMP_CharacterInfo.lineNumber;
                    bool flag2      = (num2 <= text.maxVisibleCharacters && tMP_CharacterInfo.lineNumber <= text.maxVisibleLines && (text.OverflowMode != TextOverflowModes.Page || tMP_CharacterInfo.pageNumber + 1 == text.pageToDisplay)) ? true : false;
                    if (!flag && flag2)
                    {
                        flag    = true;
                        vector  = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector2 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.bottomLeft.x, tMP_CharacterInfo.topLine, 0f));
                        if (tMP_WordInfo.characterCount == 1)
                        {
                            flag    = false;
                            vector3 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                            vector4 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.topLine, 0f));
                            if (PointIntersectRectangle(position, vector, vector2, vector4, vector3))
                            {
                                return(i);
                            }
                        }
                    }
                    if (flag && j == tMP_WordInfo.characterCount - 1)
                    {
                        flag    = false;
                        vector3 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector4 = rectTransform.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 = rectTransform.TransformPoint(new Vector3(tMP_CharacterInfo.topRight.x, tMP_CharacterInfo.bottomLine, 0f));
                        vector4 = rectTransform.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);
        }
Пример #16
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);
        }
Пример #17
0
    public override IEnumerator applyToText(TMPro.TextMeshPro text, int startIndex, int length, string param)
    {
        // Set up
        float     speed    = float.Parse(param);
        var       textInfo = text.textInfo;
        Matrix4x4 transformMatrix;

        // Cache the vertex data of the text object as the Jitter FX is applied to the original position of the characters.
        TMPro.TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();

        while (true)
        {
            //Debug.Log("shaking");
            // Get new copy of vertex data if the text has changed.
            if (hasTextChanged)
            {
                // Update the copy of the vertex data for the text object.
                cachedMeshInfo = textInfo.CopyMeshInfoVertexData();

                hasTextChanged = false;
            }
            // Applying transformations
            for (int i = startIndex; i < startIndex + length; i++)
            {
                TMPro.TMP_CharacterInfo charInfo = textInfo.characterInfo[i];

                // Skip characters that are not visible and thus have no geometry to manipulate.
                if (!charInfo.isVisible)
                {
                    continue;
                }

                // Get the index of the material used by the current character.
                int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;

                // Get the index of the first vertex used by this text element.
                int vertexIndex = textInfo.characterInfo[i].vertexIndex;

                // Get the cached vertices of the mesh used by this text element (character or sprite).
                Vector3[] sourceVertices = cachedMeshInfo[materialIndex].vertices;

                // Determine the center point of each character.
                Vector2 charMidBasline = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;

                // Need to translate all 4 vertices of each quad to aligned with middle of character / baseline.
                // This is needed so the matrix TRS is applied at the origin for each character.
                Vector3 offset = charMidBasline;

                Vector3[] destinationVertices = textInfo.meshInfo[materialIndex].vertices;

                destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] - offset;
                destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] - offset;
                destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] - offset;
                destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] - offset;

                // This stuff is what actually matters
                Vector3 jitterOffset = new Vector3(Random.Range(-1 * speed, speed), Random.Range(-1 * speed, speed), 0);

                transformMatrix = Matrix4x4.TRS(jitterOffset, Quaternion.Euler(0, 0, 0), Vector3.one);

                // Back to stuff that doesn't
                destinationVertices[vertexIndex + 0] = transformMatrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 0]);
                destinationVertices[vertexIndex + 1] = transformMatrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 1]);
                destinationVertices[vertexIndex + 2] = transformMatrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 2]);
                destinationVertices[vertexIndex + 3] = transformMatrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 3]);

                destinationVertices[vertexIndex + 0] += offset;
                destinationVertices[vertexIndex + 1] += offset;
                destinationVertices[vertexIndex + 2] += offset;
                destinationVertices[vertexIndex + 3] += offset;
            }
            // Push changes into meshes
            for (int i = 0; i < textInfo.meshInfo.Length; i++)
            {
                textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
                text.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
            }
            yield return(new WaitForSeconds(0.05f));
        }
    }
Пример #18
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);
        }
Пример #19
0
        IEnumerator DoSpriteAnimationInternal(int currentCharacter, TMP_SpriteAsset spriteAsset, int start, int end, int framerate)
        {
            if (m_TextComponent == null)
            {
                yield break;
            }

            // We yield otherwise this gets called before the sprite has rendered.
            yield return(null);

            int currentFrame = start;

            // Make sure end frame does not exceed the number of sprites in the sprite asset.
            if (end > spriteAsset.spriteInfoList.Count)
            {
                end = spriteAsset.spriteInfoList.Count - 1;
            }

            // Get a reference to the geometry of the current character.
            TMP_CharacterInfo charInfo = m_TextComponent.textInfo.characterInfo[currentCharacter];

            int materialIndex = charInfo.materialReferenceIndex;
            int vertexIndex   = charInfo.vertexIndex;

            TMP_MeshInfo meshInfo = m_TextComponent.textInfo.meshInfo[materialIndex];

            float elapsedTime = 0;
            float targetTime  = 1f / Mathf.Abs(framerate);

            while (true)
            {
                if (elapsedTime > targetTime)
                {
                    elapsedTime = 0;

                    // Get a reference to the current sprite
                    TMP_Sprite sprite = spriteAsset.spriteInfoList[currentFrame];

                    // Update the vertices for the new sprite
                    Vector3[] vertices = meshInfo.vertices;

                    Vector2 origin      = new Vector2(charInfo.origin, charInfo.baseLine);
                    float   spriteScale = charInfo.fontAsset.fontInfo.Ascender / sprite.height * sprite.scale * charInfo.scale;

                    Vector3 bl = new Vector3(origin.x + sprite.xOffset * spriteScale, origin.y + (sprite.yOffset - sprite.height) * spriteScale);
                    Vector3 tl = new Vector3(bl.x, origin.y + sprite.yOffset * spriteScale);
                    Vector3 tr = new Vector3(origin.x + (sprite.xOffset + sprite.width) * spriteScale, tl.y);
                    Vector3 br = new Vector3(tr.x, bl.y);

                    vertices[vertexIndex + 0] = bl;
                    vertices[vertexIndex + 1] = tl;
                    vertices[vertexIndex + 2] = tr;
                    vertices[vertexIndex + 3] = br;

                    // Update the UV to point to the new sprite
                    Vector2[] uvs0 = meshInfo.uvs0;

                    Vector2 uv0 = new Vector2(sprite.x / spriteAsset.spriteSheet.width, sprite.y / spriteAsset.spriteSheet.height);
                    Vector2 uv1 = new Vector2(uv0.x, (sprite.y + sprite.height) / spriteAsset.spriteSheet.height);
                    Vector2 uv2 = new Vector2((sprite.x + sprite.width) / spriteAsset.spriteSheet.width, uv1.y);
                    Vector2 uv3 = new Vector2(uv2.x, uv0.y);

                    uvs0[vertexIndex + 0] = uv0;
                    uvs0[vertexIndex + 1] = uv1;
                    uvs0[vertexIndex + 2] = uv2;
                    uvs0[vertexIndex + 3] = uv3;

                    // Update the modified vertex attributes
                    meshInfo.mesh.vertices = vertices;
                    meshInfo.mesh.uv       = uvs0;
                    m_TextComponent.UpdateGeometry(meshInfo.mesh, materialIndex);


                    if (framerate > 0)
                    {
                        if (currentFrame < end)
                        {
                            currentFrame += 1;
                        }
                        else
                        {
                            currentFrame = start;
                        }
                    }
                    else
                    {
                        if (currentFrame > start)
                        {
                            currentFrame -= 1;
                        }
                        else
                        {
                            currentFrame = end;
                        }
                    }
                }

                elapsedTime += Time.deltaTime;

                yield return(null);
            }
        }
Пример #20
0
        IEnumerator DoSpriteAnimationInternal(int currentCharacter, TMP_SpriteAsset spriteAsset, int start, int end, int framerate)
        {
            if (m_TextComponent == null)
            {
                yield break;
            }

            // We yield otherwise this gets called before the sprite has rendered.
            yield return(null);

            int currentFrame = start;

            // Make sure end frame does not exceed the number of sprites in the sprite asset.
            if (end > spriteAsset.spriteCharacterTable.Count)
            {
                end = spriteAsset.spriteCharacterTable.Count - 1;
            }

            // Get a reference to the current character's info
            TMP_CharacterInfo charInfo = m_TextComponent.textInfo.characterInfo[currentCharacter];

            int materialIndex = charInfo.materialReferenceIndex;
            int vertexIndex   = charInfo.vertexIndex;

            TMP_MeshInfo meshInfo = m_TextComponent.textInfo.meshInfo[materialIndex];

            float baseSpriteScale = spriteAsset.spriteCharacterTable[start].scale * spriteAsset.spriteCharacterTable[start].glyph.scale;

            float elapsedTime = 0;
            float targetTime  = 1f / Mathf.Abs(framerate);

            while (true)
            {
                if (elapsedTime > targetTime)
                {
                    elapsedTime = 0;

                    // Return if sprite was truncated or replaced by the Ellipsis character.
                    char character = m_TextComponent.textInfo.characterInfo[currentCharacter].character;
                    if (character == 0x03 || character == 0x2026)
                    {
                        m_animations.Remove(currentCharacter);
                        yield break;
                    }

                    // Get a reference to the current sprite
                    TMP_SpriteCharacter spriteCharacter = spriteAsset.spriteCharacterTable[currentFrame];

                    // Update the vertices for the new sprite
                    Vector3[] vertices = meshInfo.vertices;

                    Vector2 origin = new Vector2(charInfo.origin, charInfo.baseLine);

                    float spriteScale = charInfo.scale / baseSpriteScale * spriteCharacter.scale * spriteCharacter.glyph.scale;

                    Vector3 bl = new Vector3(origin.x + spriteCharacter.glyph.metrics.horizontalBearingX * spriteScale, origin.y + (spriteCharacter.glyph.metrics.horizontalBearingY - spriteCharacter.glyph.metrics.height) * spriteScale);
                    Vector3 tl = new Vector3(bl.x, origin.y + spriteCharacter.glyph.metrics.horizontalBearingY * spriteScale);
                    Vector3 tr = new Vector3(origin.x + (spriteCharacter.glyph.metrics.horizontalBearingX + spriteCharacter.glyph.metrics.width) * spriteScale, tl.y);
                    Vector3 br = new Vector3(tr.x, bl.y);

                    vertices[vertexIndex + 0] = bl;
                    vertices[vertexIndex + 1] = tl;
                    vertices[vertexIndex + 2] = tr;
                    vertices[vertexIndex + 3] = br;

                    // Update the UV to point to the new sprite
                    Vector2[] uvs0 = meshInfo.uvs0;

                    Vector2 uv0 = new Vector2((float)spriteCharacter.glyph.glyphRect.x / spriteAsset.spriteSheet.width, (float)spriteCharacter.glyph.glyphRect.y / spriteAsset.spriteSheet.height);
                    Vector2 uv1 = new Vector2(uv0.x, (float)(spriteCharacter.glyph.glyphRect.y + spriteCharacter.glyph.glyphRect.height) / spriteAsset.spriteSheet.height);
                    Vector2 uv2 = new Vector2((float)(spriteCharacter.glyph.glyphRect.x + spriteCharacter.glyph.glyphRect.width) / spriteAsset.spriteSheet.width, uv1.y);
                    Vector2 uv3 = new Vector2(uv2.x, uv0.y);

                    uvs0[vertexIndex + 0] = uv0;
                    uvs0[vertexIndex + 1] = uv1;
                    uvs0[vertexIndex + 2] = uv2;
                    uvs0[vertexIndex + 3] = uv3;

                    // Update the modified vertex attributes
                    meshInfo.mesh.vertices = vertices;
                    meshInfo.mesh.uv       = uvs0;
                    m_TextComponent.UpdateGeometry(meshInfo.mesh, materialIndex);


                    if (framerate > 0)
                    {
                        if (currentFrame < end)
                        {
                            currentFrame += 1;
                        }
                        else
                        {
                            currentFrame = start;
                        }
                    }
                    else
                    {
                        if (currentFrame > start)
                        {
                            currentFrame -= 1;
                        }
                        else
                        {
                            currentFrame = end;
                        }
                    }
                }

                elapsedTime += Time.deltaTime;

                yield return(null);
            }
        }
Пример #21
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);
        }