Ejemplo n.º 1
0
 public TMP_TextInfo()
 {
     characterInfo = new TMP_CharacterInfo[0];
     wordInfo      = new List <TMP_WordInfo>(32);
     lineInfo      = new TMP_LineInfo[16];
     pageInfo      = new TMP_PageInfo[8];
     meshInfo      = default(TMP_MeshInfo);
 }
Ejemplo n.º 2
0
 public TMP_TextInfo()
 {
     this.characterInfo       = new TMP_CharacterInfo[0];
     this.wordInfo            = new List <TMP_WordInfo>(32);
     this.lineInfo            = new TMP_LineInfo[16];
     this.pageInfo            = new TMP_PageInfo[16];
     this.meshInfo            = default(TMP_MeshInfo);
     this.meshInfo.meshArrays = new UIVertex[17][];
 }
        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);
            }
        }
Ejemplo n.º 4
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);
            }
        }
        // Default Constructor
        public TMP_TextInfo()
        {
            characterInfo = new TMP_CharacterInfo[0];
            wordInfo      = new List <TMP_WordInfo>(32);
            lineInfo      = new TMP_LineInfo[16];
            pageInfo      = new TMP_PageInfo[16];

            meshInfo = new TMP_MeshInfo();
#if UNITY_4_6 || UNITY_5
            meshInfo.meshArrays = new UIVertex[17][];
#endif

            //characterInfoList = new List<TMP_CharacterInfo>(128);
            //wordInfoList = new List<TMP_WordInfo>(64);
            //lineInfoList = new List<TMP_LineInfo>(32);
            //pageInfoList = new List<TMP_PageInfo>(16);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        // Default Constructor
        public TMP_TextInfo()
        {
            characterInfo = new TMP_CharacterInfo[0];
            wordInfo = new List<TMP_WordInfo>(32);
            lineInfo = new TMP_LineInfo[16];
            pageInfo = new TMP_PageInfo[16];

            meshInfo = new TMP_MeshInfo();
#if UNITY_4_6 || UNITY_5
            meshInfo.meshArrays = new UIVertex[17][];
#endif
            
            //characterInfoList = new List<TMP_CharacterInfo>(128);
            //wordInfoList = new List<TMP_WordInfo>(64);
            //lineInfoList = new List<TMP_LineInfo>(32);
            //pageInfoList = new List<TMP_PageInfo>(16);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        // Default Constructor
        public TMP_TextInfo()
        {
            characterInfo = new TMP_CharacterInfo[0];
            wordInfo = new List<TMP_WordInfo>(32);
            linkInfo = new List<TMP_LinkInfo>(4);
            lineInfo = new TMP_LineInfo[16];
            pageInfo = new TMP_PageInfo[16];

            meshInfo = new TMP_MeshInfo();
        }
Ejemplo n.º 10
0
        public void DrawMesh()
        {
            TMP_MeshInfo meshInfo = m_textMeshProComponent.textInfo.meshInfo;
            TMP_TextInfo textInfo = m_textMeshProComponent.textInfo;

            TMP_CharacterInfo[] characterInfo = textInfo.characterInfo;
            int characterCount = textInfo.characterCount;

            Vector3[] vertices     = meshInfo.vertices;
            Vector2[] uv0s         = meshInfo.uv0s;
            Vector2[] uv2s         = meshInfo.uv2s;
            Color32[] vertexColors = meshInfo.vertexColors;
            Vector3[] normals      = meshInfo.normals;
            Vector4[] tangents     = meshInfo.tangents;
            float     num          = 1f;
            float     num2         = 0f;
            float     num3         = 0f;

            for (int i = 0; i < characterCount; i++)
            {
                char      character   = characterInfo[i].character;
                GlyphInfo glyphInfo   = m_textMeshProComponent.font.characterDictionary[character];
                int       vertexIndex = characterInfo[i].vertexIndex;
                if (characterInfo[i].isVisible)
                {
                    float   x = (characterInfo[i].bottomLeft.x + characterInfo[i].topRight.x) / 2f;
                    Vector3 a = new Vector3(x, 0f, 0f);
                    vertices[vertexIndex]     += -a;
                    vertices[vertexIndex + 1] += -a;
                    vertices[vertexIndex + 2] += -a;
                    vertices[vertexIndex + 3] += -a;
                    float time = (characterCount <= 1) ? 0f : ((float)i / (float)(characterCount - 1));
                    num2 = ScaleCurve.Evaluate(time);
                    Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(0f, 0f, 0f), Quaternion.Euler(0f, 0f, 0f), new Vector3(num2, num2, 1f));
                    vertices[vertexIndex]     = matrix4x.MultiplyPoint3x4(vertices[vertexIndex]);
                    vertices[vertexIndex + 1] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 1]);
                    vertices[vertexIndex + 2] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 2]);
                    vertices[vertexIndex + 3] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 3]);
                    float num4 = glyphInfo.xOffset * characterInfo[i].scale * num2 + (characterInfo[i].topRight.x - characterInfo[i].bottomLeft.x) / 2f * num2;
                    a = new Vector3(num4 + num3, 0f, 0f);
                    vertices[vertexIndex]     += a;
                    vertices[vertexIndex + 1] += a;
                    vertices[vertexIndex + 2] += a;
                    vertices[vertexIndex + 3] += a;
                    uv2s[vertexIndex].y       *= num2;
                    uv2s[vertexIndex + 1].y   *= num2;
                    uv2s[vertexIndex + 2].y   *= num2;
                    uv2s[vertexIndex + 3].y   *= num2;
                }
                num3 += glyphInfo.xAdvance * characterInfo[i].scale * num2 + m_textMeshProComponent.characterSpacing;
            }
            int   vertexIndex2 = characterInfo[characterCount - 1].vertexIndex;
            float x2           = vertices[0].x;
            float x3           = vertices[vertexIndex2 + 2].x;

            for (int j = 0; j < characterCount; j++)
            {
                int vertexIndex3 = characterInfo[j].vertexIndex;
                if (characterInfo[j].isVisible)
                {
                    float   num5   = (vertices[vertexIndex3].x + vertices[vertexIndex3 + 2].x) / 2f;
                    Vector3 vector = new Vector3(num5, 0f, 0f);
                    vertices[vertexIndex3]     += -vector;
                    vertices[vertexIndex3 + 1] += -vector;
                    vertices[vertexIndex3 + 2] += -vector;
                    vertices[vertexIndex3 + 3] += -vector;
                    float   num6 = (num5 - x2) / (x3 - x2);
                    float   num7 = num6 + 0.0001f;
                    float   num8 = TranslationCurve.Evaluate(num6) * num;
                    float   num9 = TranslationCurve.Evaluate(num7) * num;
                    Vector3 lhs  = new Vector3(1f, 0f, 0f);
                    Debug.DrawLine(end: new Vector3(0f - (num9 - num8), num7 * (x3 - x2) + x2 - num5, 0f), start: new Vector3(num5, num8, 0f), color: Color.green, duration: 60f);
                    Vector3   rhs      = new Vector3(num7 * (x3 - x2) + x2, num9) - new Vector3(num5, num8);
                    float     num10    = Mathf.Acos(Vector3.Dot(lhs, rhs.normalized)) * 57.29578f;
                    Vector3   vector2  = Vector3.Cross(lhs, rhs);
                    float     z        = (!(vector2.z > 0f)) ? (360f - num10) : num10;
                    Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(0f, num8, 0f), Quaternion.Euler(0f, 0f, z), new Vector3(1f, 1f, 1f));
                    vertices[vertexIndex3]      = matrix4x.MultiplyPoint3x4(vertices[vertexIndex3]);
                    vertices[vertexIndex3 + 1]  = matrix4x.MultiplyPoint3x4(vertices[vertexIndex3 + 1]);
                    vertices[vertexIndex3 + 2]  = matrix4x.MultiplyPoint3x4(vertices[vertexIndex3 + 2]);
                    vertices[vertexIndex3 + 3]  = matrix4x.MultiplyPoint3x4(vertices[vertexIndex3 + 3]);
                    vertices[vertexIndex3]     += vector;
                    vertices[vertexIndex3 + 1] += vector;
                    vertices[vertexIndex3 + 2] += vector;
                    vertices[vertexIndex3 + 3] += vector;
                }
            }
            Mesh mesh = m_textMeshProComponent.mesh;

            mesh.vertices = vertices;
            mesh.uv       = uv0s;
            mesh.uv2      = uv2s;
            mesh.colors32 = vertexColors;
            if (m_sharedMaterial.HasProperty(ShaderUtilities.ID_Shininess))
            {
                mesh.normals  = normals;
                mesh.tangents = tangents;
            }
            mesh.RecalculateBounds();
        }