Esempio n. 1
0
        void ON_TEXT_CHANGED(Object obj)
        {
            if (obj == textToReveal)
            {
                if (lastStr != textToReveal.text)
                {
                    lastStr = textToReveal.text;
                    for (int index = 0; index < textToReveal.textInfo.meshInfo.Length; index++)
                    {
                        for (int index2 = 0; index2 < textToReveal.textInfo.meshInfo[index].colors32.Length; index2++)
                        {
                            textToReveal.textInfo.meshInfo[index].colors32[index2].a = (byte)0;
                        }
                    }
                    textToReveal.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                    hasTextChanged = true;
                }
                else
                if (init)
                {
                    for (int index = 0; index < textToReveal.textInfo.meshInfo.Length; index++)
                    {
                        for (int index2 = 0; index2 < textToReveal.textInfo.meshInfo[index].colors32.Length; index2++)
                        {
                            textToReveal.textInfo.meshInfo[index].colors32[index2].a = (byte)0;
                        }
                    }
                    textToReveal.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                    init = false;
                }
            }
        }
Esempio n. 2
0
    public void FinishReveal()
    {
        int          numCharacters = m_TextComponent.textInfo.characterCount;
        TMP_TextInfo textInfo      = m_TextComponent.textInfo;

        for (int i = 0; i < numCharacters; i++)
        {
            int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;

            // Get the vertex colors of the mesh used by this text element (character or sprite).
            Color32[] newVertexColors = textInfo.meshInfo[materialIndex].colors32;

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

            // Set new alpha values.
            newVertexColors[vertexIndex + 0].a = 255;
            newVertexColors[vertexIndex + 1].a = 255;
            newVertexColors[vertexIndex + 2].a = 255;
            newVertexColors[vertexIndex + 3].a = 255;
        }
        m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

        finished = true;
    }
Esempio n. 3
0
        IEnumerator AnimateVertexColors()
        {
            // Need to force the text object to be generated so we have valid data to work with right from the start.
            _textComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo = _textComponent.textInfo;

            //Turn off all characters
            int characterCount = textInfo.characterCount;

            for (int i = 0; i < characterCount; i++)
            {
                SetAlpha(textInfo, i, 0);
            }

            _textComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

            for (int i = 0; i < characterCount; i++)
            {
                SetAlpha(textInfo, i, 255);
                _textComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                yield return(new WaitForSeconds(0.1f));
            }
        }
Esempio n. 4
0
    private void ShowCharacter(int i, TMP_TextInfo textInfo, Color32 c0)
    {
        //Color of all chracters vertices
        Color32[] newVertexColors;

        //Instead of incrementing maxVisibleCharacters or add the current character to our string, we do this :

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

        // Get the vertex colors of the mesh used by this text element (character or sprite).
        newVertexColors = textInfo.meshInfo[materialIndex].colors32;

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

        // Only change the vertex color if the text element is visible. (It's visible, only the alpha color is 0)
        if (textInfo.characterInfo[i].isVisible)
        {
            newVertexColors[vertexIndex + 0] = c0;
            newVertexColors[vertexIndex + 1] = c0;
            newVertexColors[vertexIndex + 2] = c0;
            newVertexColors[vertexIndex + 3] = c0;

            // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
            SentenceUIObject.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
        }
    }
Esempio n. 5
0
    void SetLinkToColor(int linkIndex, Color32 color)
    {
        TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];


        for (int i = 0; i < linkInfo.linkTextLength; i++)
        {                                                                                // for each character in the link string
            int characterIndex = linkInfo.linkTextfirstCharacterIndex + i;               // the character index into the entire text
            var charInfo       = pTextMeshPro.textInfo.characterInfo[characterIndex];
            int meshIndex      = charInfo.materialReferenceIndex;                        // Get the index of the material / sub text object used by this character.
            int vertexIndex    = charInfo.vertexIndex;                                   // Get the index of the first vertex of this character.

            Color32[] vertexColors = pTextMeshPro.textInfo.meshInfo[meshIndex].colors32; // the colors for this character
            oldVertColors.Add(vertexColors.ToArray());

            if (charInfo.isVisible)
            {
                vertexColors[vertexIndex + 0] = color;
                vertexColors[vertexIndex + 1] = color;
                vertexColors[vertexIndex + 2] = color;
                vertexColors[vertexIndex + 3] = color;
            }
        }

        // Update Geometry
        pTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
    }
Esempio n. 6
0
    IEnumerator AnimateCoroutine()
    {
        int currentCharacter = 0;

        text.color = new Color32(255, 255, 255, 0);
        text.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

        yield return(new WaitForSeconds(0.25f));

        int characterCount = text.textInfo.characterCount;

        while (currentCharacter < text.textInfo.characterCount)
        {
            var textInfo = text.textInfo;

            if (characterCount == 0)
            {
                yield return(new WaitForSeconds(0.25f));

                continue;
            }

            int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;

            var vertexColors = textInfo.meshInfo[materialIndex].colors32;

            int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;

            vertexColors[vertexIndex + 0] = colorVisible;
            vertexColors[vertexIndex + 1] = colorVisible;
            vertexColors[vertexIndex + 2] = colorVisible;
            vertexColors[vertexIndex + 3] = colorVisible;

            text.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);


            var character = textInfo.characterInfo[currentCharacter].character;

            if (character == ',' || character == ';' || character == '\n')
            {
                yield return(new WaitForSeconds(commaDelay));
            }
            else if (character == ' ')
            {
                yield return(new WaitForSeconds(spaceDelay));
            }
            else if (currentCharacter % 2 == 0)
            {
                PlayAudio(audioClip, pitchShiftCurve.Evaluate(Random.value));
            }

            yield return(new WaitForSeconds(Random.Range(minWait, maxWait)));

            currentCharacter += 1;
        }
    }
Esempio n. 7
0
    public void ChangeWordColor(TMP_WordInfo wInfo, Color32 color)
    {
        for (int i = 0; i < wInfo.characterCount; i++)
        {
            int characterIndex      = wInfo.firstCharacterIndex + i;
            TMP_CharacterInfo cInfo = m_TextComponent.textInfo.characterInfo[characterIndex];
            ChangeLetterColor(m_TextComponent, cInfo, color);
        }

        // Update Geometry
        m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
    }
Esempio n. 8
0
        IEnumerator FadeInCharacter(int materialIndex, int vertexIndex, int currentCharacter)
        {
            TMP_TextInfo textInfo = m_TextComponent.textInfo;

            Color32[] newVertexColors;
            Color32   c0 = m_TextComponent.color;

            // Get the vertex colors of the mesh used by this text element (character or sprite).
            newVertexColors = textInfo.meshInfo[materialIndex].colors32;

            float alpha     = 0f;
            float fadeToOne = 0f;

            while (alpha < 255)
            {
                fadeToOne += Time.deltaTime / fadeInDur;
                alpha      = fadeToOne * 255;
                if (alpha > 255)
                {
                    alpha = 255;
                }
                //Debug.Log(alpha);

                if (textInfo.characterInfo[currentCharacter].isVisible)
                {
                    c0 = new Color32(255, 255, 255, (byte)alpha);

                    newVertexColors[vertexIndex + 0] = c0;
                    newVertexColors[vertexIndex + 1] = c0;
                    newVertexColors[vertexIndex + 2] = c0;
                    newVertexColors[vertexIndex + 3] = c0;

                    // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
                    m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                    // This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
                    // These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
                }
                yield return(null);
            }
            c0 = new Color32(255, 255, 255, 255);

            newVertexColors[vertexIndex + 0] = c0;
            newVertexColors[vertexIndex + 1] = c0;
            newVertexColors[vertexIndex + 2] = c0;
            newVertexColors[vertexIndex + 3] = c0;

            // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
            m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

            yield return(null);
        }
Esempio n. 9
0
    void ResetGeometry()
    {
        TMP_TextInfo textInfo = m_TextComponent.textInfo;

        for (int i = 0; i < textInfo.meshInfo.Length; i++)
        {
            var newVertexPositions = textInfo.meshInfo[i].vertices;

            // Upload the mesh with the revised information
            UpdateMesh(newVertexPositions, 0);
        }

        m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
        m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
    }
Esempio n. 10
0
        /// <summary>
        /// 255文字後の文字が赤いのなる
        /// </summary>
        void UpdateTextCharactor()
        {
            tmpText = inputFieldText.GetComponent <TMP_Text>();
            Color32 c0 = tmpText.color;

            textInfo = tmpText.textInfo;
            var red0 = new Color(1, 150f / 255, 0 / 255, 1);
            var red1 = new Color(1, 80f / 255, 0 / 255, 1);
            var red2 = new Color(1, 0, 0, 1);

            for (int i = 0; i < textInfo.characterCount; i++)
            {
                int materialIndex   = textInfo.characterInfo[i].materialReferenceIndex;
                int vertexIndex     = textInfo.characterInfo[i].vertexIndex;
                var newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                if (textInfo.characterInfo[i].isVisible)
                {
                    if (i >= CharacterLimit)
                    {
                        newVertexColors[vertexIndex + 0] = red1;
                        newVertexColors[vertexIndex + 1] = red0;
                        newVertexColors[vertexIndex + 2] = red1;
                        newVertexColors[vertexIndex + 3] = red2;
                    }
                    else
                    {
                        newVertexColors[vertexIndex + 0] = c0;
                        newVertexColors[vertexIndex + 1] = c0;
                        newVertexColors[vertexIndex + 2] = c0;
                        newVertexColors[vertexIndex + 3] = c0;
                    }
                }
            }
            tmpText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
        }
Esempio n. 11
0
    public void FadeIn()
    {
        currentTime += Time.deltaTime;
        float t = currentTime / fadeTime;

        t = Mathf.Sin(t * Mathf.PI * 0.5f);

        alpha = Mathf.Lerp(0, 255, t);

        //alpha = Mathf.Lerp (alpha, 255, Time.deltaTime / fadeTime);
        characterColor = new Color32((byte)characterColor.r, (byte)characterColor.g, (byte)characterColor.g, (byte)alpha);

        for (int i = 0; i < textInfo.characterCount; i++)
        {
            int       materialIndex   = textInfo.characterInfo [i].materialReferenceIndex;
            Color32[] newVertexColors = textInfo.meshInfo [materialIndex].colors32;
            int       vertexIndex     = textInfo.characterInfo [i].vertexIndex;

            newVertexColors [vertexIndex + 0] = characterColor;
            newVertexColors [vertexIndex + 1] = characterColor;
            newVertexColors [vertexIndex + 2] = characterColor;
            newVertexColors [vertexIndex + 3] = characterColor;
        }
        m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
    }
    private void SetSkew()
    {
        CachedTextComponent.ForceMeshUpdate();
        TMP_TextInfo textInfo       = m_TextComponent.textInfo;
        int          characterCount = textInfo.characterCount;

        if (characterCount == 0)
        {
            return;
        }

        float boundsMinX = CachedTextComponent.bounds.min.x;
        float boundsMaxX = CachedTextComponent.bounds.max.x;

        for (int i = 0; i < characterCount; i++)
        {
            if (!textInfo.characterInfo[i].isVisible)
            {
                continue;
            }

            int vertexIndex = textInfo.characterInfo[i].vertexIndex;

            int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;

            vertices = textInfo.meshInfo[materialIndex].vertices;

            vertices[vertexIndex + 0].x += xSkew;
            vertices[vertexIndex + 3].x += xSkew;

            // Upload the mesh with the revised information
            m_TextComponent.UpdateVertexData();
        }
    }
Esempio n. 13
0
    /// <summary>
    ///  Method that makes a single character "wave" along a Unity animation curve.
    /// </summary>
    /// <param name="textComponent"></param>
    /// <returns></returns>
    IEnumerator ContinuousWave(Vector3[] vertices, int materialIndex, int vertexIndex, int currentCharacter)
    {
        float timer = 0f;

        float originalY0 = vertices[vertexIndex + 0].y;
        float originalY1 = vertices[vertexIndex + 1].y;
        float originalY2 = vertices[vertexIndex + 2].y;
        float originalY3 = vertices[vertexIndex + 3].y;

        while (waving)
        {
            timer += Time.deltaTime / waveDur;
            // Compute the Y offset for each character.
            float yOffset = (waveCurve.Evaluate(timer) * curveScale);
            // Apply offset to adjust our pivot point.
            vertices[vertexIndex + 0].y = originalY0 + yOffset;
            vertices[vertexIndex + 1].y = originalY1 + yOffset;
            vertices[vertexIndex + 2].y = originalY2 + yOffset;
            vertices[vertexIndex + 3].y = originalY3 + yOffset;
            // Upload the mesh with the revised information.
            m_TextComponent.UpdateVertexData();
            // When to force update the vertices.
            updateAfterCount++;
            // Update every x seconds.
            yield return(null);
        }
    }
Esempio n. 14
0
        private void SetLinkToColor(int linkIndex, Color32 color)
        {
            TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];

            if (linkInfo.textComponent != null)
            {
                for (int i = 0; i < linkInfo.linkTextLength; i++)
                {
                    int characterIndex = linkInfo.linkTextfirstCharacterIndex + i;                     // the character index into the entire text
                    var charInfo       = pTextMeshPro.textInfo.characterInfo[characterIndex];
                    if (charInfo.character != ' ')
                    {
                        int meshIndex   = charInfo.materialReferenceIndex;              // Get the index of the material / sub text object used by this character.
                        int vertexIndex = charInfo.vertexIndex;                         // Get the index of the first vertex of this character.

                        Color32[] vertexColors = pTextMeshPro.textInfo.meshInfo[meshIndex].colors32;
                        vertexColors[vertexIndex + 0] = color;
                        vertexColors[vertexIndex + 1] = color;
                        vertexColors[vertexIndex + 2] = color;
                        vertexColors[vertexIndex + 3] = color;
                    }
                }
            }

            pTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
        }
Esempio n. 15
0
        /// <summary>
        /// メッシューの色の変更
        /// </summary>
        protected IEnumerator AnimateVertexColors()
        {
            TMP_TextInfo textInfo         = tmpText.textInfo;
            int          currentCharacter = 0;

            Color32[] newVertexColors;
            Color32   c0             = tmpText.color;
            int       characterCount = textInfo.characterCount;

            if (characterCount == 0)
            {
                yield return(new WaitForSeconds(ColorUpdateInterval));
            }
            for (int i = 0; i < textInfo.characterCount; i++)
            {
                int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[i].vertexIndex;
                if (textInfo.characterInfo[i].isVisible)
                {
                    c0 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), newVertexColors[vertexIndex].a);
                    newVertexColors[vertexIndex + 0] = c0;
                    newVertexColors[vertexIndex + 1] = c0;
                    newVertexColors[vertexIndex + 2] = c0;
                    newVertexColors[vertexIndex + 3] = c0;
                }
            }
            tmpText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            while (true)
            {
                int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
                if (textInfo.characterInfo[currentCharacter].isVisible)
                {
                    c0 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), newVertexColors[vertexIndex].a);
                    newVertexColors[vertexIndex + 0] = c0;
                    newVertexColors[vertexIndex + 1] = c0;
                    newVertexColors[vertexIndex + 2] = c0;
                    newVertexColors[vertexIndex + 3] = c0;
                }
                currentCharacter = (currentCharacter + 1) % characterCount;
                tmpText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
                yield return(new WaitForSeconds(ColorUpdateInterval));
            }
        }
Esempio n. 16
0
    IEnumerator AnimateVertexColors()
    {
        // Force the text object to update right away so we can have geometry to modify right from the start.
        m_TextComponent.ForceMeshUpdate();

        TMP_TextInfo textInfo = m_TextComponent.textInfo;

        Color32[] newVertexColors;
        Color32   c0 = m_TextComponent.color;

        while (true)
        {
            int characterCount = textInfo.characterCount;

            // If No Characters then just yield and wait for some text to be added
            if (characterCount == 0)
            {
                yield return(new WaitForSeconds(0.25f));

                continue;
            }

            for (int currentCharacter = 0; currentCharacter < characterCount; currentCharacter++)
            {
                int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;

                if (!textInfo.characterInfo[currentCharacter].isVisible)
                {
                    continue;
                }


                int r = 255;
                int g = 255;
                int b = 0;
                if (!active)
                {
                    b = 255;
                }
                int a = 255;



                c0 = new Color32((byte)r, (byte)g, (byte)b, (byte)a);


                newVertexColors[vertexIndex + 0] = c0;
                newVertexColors[vertexIndex + 1] = c0;
                newVertexColors[vertexIndex + 2] = c0;
                newVertexColors[vertexIndex + 3] = c0;
                m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }

            yield return(new WaitForSeconds(0.005f));
        }
    }
Esempio n. 17
0
 private void UpdateVertexColors(Color32[] newVertexColors, int vertexIndex, Color32 color, TMP_Text dialogueBox)
 {
     newVertexColors[vertexIndex + 0] = color;
     newVertexColors[vertexIndex + 1] = color;
     newVertexColors[vertexIndex + 2] = color;
     newVertexColors[vertexIndex + 3] = color;
     // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
     dialogueBox.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
 }
Esempio n. 18
0
    IEnumerator StartWave()
    {
        waving = true;
        int loopCount = 0;

        VertexCurve.preWrapMode  = WrapMode.Loop;
        VertexCurve.postWrapMode = WrapMode.Loop;

        Vector3[] vertices;
        Vector3[] newVertexPositions;

        while (true)
        {
            m_TextComponent.renderMode = TextRenderFlags.DontRender; // Instructing TextMesh Pro not to upload the mesh as we will be modifying it.
            m_TextComponent.ForceMeshUpdate();                       // Generate the mesh and populate the textInfo with data we can use and manipulate.

            TMP_TextInfo textInfo       = m_TextComponent.textInfo;
            int          characterCount = textInfo.characterCount;
            // Get the index of the mesh used by this character.
            int matIndex = textInfo.characterInfo[0].materialReferenceIndex;
            // Get the index of the first vertex used by this text element.
            int vertIndex = textInfo.characterInfo[0].vertexIndex;

            newVertexPositions = textInfo.meshInfo[matIndex].vertices;

            for (int i = 0; i < characterCount; i++)
            {
                if (!textInfo.characterInfo[i].isVisible)
                {
                    continue;
                }
                // Get the index of the mesh used by this character.
                matIndex = textInfo.characterInfo[i].materialReferenceIndex;
                // Get the index of the first vertex used by this text element.
                vertIndex = textInfo.characterInfo[i].vertexIndex;

                vertices = textInfo.meshInfo[matIndex].vertices;

                float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f) * CurveScale;                 // Random.Range(-0.25f, 0.25f);
                // Compute the baseline mid point for each character
                // Vector3 offsetToMidBaseline = new Vector2(0f, VertexCurve.Evaluate(timer) + (timeBetweenChar * (i + 1)) * yMultiplier);
                // Apply offset to adjust our pivot point.
                vertices[vertIndex + 0].y += offsetY;
                vertices[vertIndex + 1].y += offsetY;
                vertices[vertIndex + 2].y += offsetY;
                vertices[vertIndex + 3].y += offsetY;
            }
            loopCount++;
            // Upload the mesh with the revised information
            m_TextComponent.UpdateVertexData();
            // Delay between every text character.
            //yield return null;
            yield return(new WaitForSeconds(0.025f));
        }
    }
Esempio n. 19
0
        /// <summary>
        ///     Method to animate vertex colors of a TMP Text object.
        /// </summary>
        /// <returns></returns>
        IEnumerator AnimateVertexColors()
        {
            // Force the text object to update right away so we can have geometry to modify right from the start.
            m_TextComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo         = m_TextComponent.textInfo;
            int          currentCharacter = 0;

            Color32[] newVertexColors;
            Color32   c0 = m_TextComponent.color;

            while (true)
            {
                int characterCount = textInfo.characterCount;

                // If No Characters then just yield and wait for some text to be added
                if (characterCount == 0)
                {
                    yield return(new WaitForSeconds(0.25f));

                    continue;
                }

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

                // Get the vertex colors of the mesh used by this text element (character or sprite).
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;

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

                // Only change the vertex color if the text element is visible.
                if (textInfo.characterInfo[currentCharacter].isVisible)
                {
                    c0 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255),
                                     (byte)Random.Range(0, 255), 255);

                    newVertexColors[vertexIndex + 0] = c0;
                    newVertexColors[vertexIndex + 1] = c0;
                    newVertexColors[vertexIndex + 2] = c0;
                    newVertexColors[vertexIndex + 3] = c0;

                    // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
                    m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                    // This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
                    // These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
                }

                currentCharacter = (currentCharacter + 1) % characterCount;

                yield return(new WaitForSeconds(0.05f));
            }
        }
        /* ======================================== *\
         *                FUNCTIONS                 *
        \* ======================================== */

        private void SetLetterTransparent()
        {

            for (int i = 0; i < textMeshPro.textInfo.characterCount; i++)
            {
                int vertexIndex = textMeshPro.textInfo.characterInfo[i].vertexIndex;

                int materialIndex = textMeshPro.textInfo.characterInfo[i].materialReferenceIndex;

                Color32[] newVertexColors = textMeshPro.textInfo.meshInfo[materialIndex].colors32;

                Color32 colorAlpha = new Color32(255, 255, 255, 0);
                newVertexColors[vertexIndex + 0] = colorAlpha;
                newVertexColors[vertexIndex + 1] = colorAlpha;
                newVertexColors[vertexIndex + 2] = colorAlpha;
                newVertexColors[vertexIndex + 3] = colorAlpha;

                textMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }
        }
Esempio n. 21
0
        // Update is called once per frame after all updates
        IEnumerator Movement()
        {
            text.ForceMeshUpdate();

            TMP_TextInfo textInfo = text.textInfo;

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

            hasTextChanged = true;

            while (true)
            {
                // Allocate new vertices
                if (hasTextChanged)
                {
                    // Update the copy of the vertex data for the text object.
                    cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
                    hasTextChanged = false;
                }

                int characterCount = textInfo.characterCount;

                // If No Characters then just yield and wait for some text to be added
                if (characterCount == 0)
                {
                    yield return(new WaitForSeconds(0.25f));

                    continue;
                }

                //TODO: MY CODE HERE
                switch (movement)
                {
                case MovementType.None:
                    yield return(new WaitForSeconds(0.25f));

                    continue;

                case MovementType.Breath:
                    Breath(ref textInfo, ref cachedMeshInfo);
                    break;
                }
                //MY CODE END

                // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
                text.UpdateVertexData(TMP_VertexDataUpdateFlags.Vertices);

                yield return(new WaitForSeconds(0.1f));
            }
        }
Esempio n. 22
0
    public void HighlightChar()
    {
        //print("DisplayWord");
        TMP_TextInfo textInfo = tmpText.textInfo;

        Color32[] newVertexColors;
        Color32   c0 = tmpText.color;

        int characterCount = textInfo.characterCount;

        if (characterCount == 0)
        {
            return;
        }

        int materialIndex = textInfo.characterInfo[currChar].materialReferenceIndex;

        newVertexColors = textInfo.meshInfo[materialIndex].colors32;
        int vertexIndex = textInfo.characterInfo[currChar].vertexIndex;

        if (textInfo.characterInfo[currChar].isVisible)
        {
            c0 = new Color32(255, 0, 255, 255);

            newVertexColors[vertexIndex + 0] = c0;
            newVertexColors[vertexIndex + 1] = c0;
            newVertexColors[vertexIndex + 2] = c0;
            newVertexColors[vertexIndex + 3] = c0;

            // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
            tmpText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

            // This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
            // These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
        }

        tmpText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
    }
Esempio n. 23
0
    private void SetText()
    {
        for (int i = 0; i < currentIndex; ++i)
        {
            int meshIndex   = text.textInfo.characterInfo[i].materialReferenceIndex;
            int vertexIndex = text.textInfo.characterInfo[i].vertexIndex;

            Color32[] vertexColors = text.textInfo.meshInfo[meshIndex].colors32;
            vertexColors[vertexIndex + 0] = grayColor;
            vertexColors[vertexIndex + 1] = grayColor;
            vertexColors[vertexIndex + 2] = grayColor;
            vertexColors[vertexIndex + 3] = grayColor;
        }

        text.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
    }
Esempio n. 24
0
    IEnumerator AnimateVertexColors()
    {
        // Force the text object to update right away so we can have geometry to modify right from the start.
        m_TextComponent.ForceMeshUpdate();

        TMP_TextInfo textInfo = m_TextComponent.textInfo;

        Color32[] newVertexColors;

        while (true)
        {
            int characterCount = textInfo.characterCount;

            // If No Characters then just yield and wait for some text to be added
            if (characterCount == 0)
            {
                yield return(new WaitForSeconds(0.25f));

                continue;
            }

            for (int currentCharacter = 0; currentCharacter < characterCount; currentCharacter++)
            {
                if (currentCharacter < waveEnd)
                {
                    // Might take some time lol
                }

                if (currentCharacter < fadeEnd)
                {
                    int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                    newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                    int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;

                    for (int i = 0; i < 4; i++)
                    {
                        newVertexColors[vertexIndex + i].a = (byte)Math.Max(0, newVertexColors[vertexIndex + i].a - 1);
                    }
                    m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
                }
            }

            yield return(new WaitForSeconds(0.02f));
        }
    }
        private IEnumerator RandomTextColorFill()
        {
            var currentCharacter = 0;
            var characterCount   = _tmpText.text.Length;

            var c0 = new Color32(0, 255, 0, 255);
            var c1 = new Color32(0, 0, 0, 127);

            while (true)
            {
                if (currentCharacter == characterCount)
                {
                    yield return(new WaitForSeconds(0.20f));

                    break;
                }

                if (currentCharacter == 0)
                {
                    c0 = new Color32((byte)Random.Range(0, 255),
                                     (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
                }

                var matIndex        = _textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                var vertexIndex     = _textInfo.characterInfo[currentCharacter].vertexIndex;
                var newVertexColors = _textInfo.meshInfo[matIndex].colors32;

                if (_textInfo.characterInfo[currentCharacter].isVisible)
                {
                    c0 = newVertexColors[vertexIndex + 0] = c0;
                    newVertexColors[vertexIndex + 1] = c1;
                    newVertexColors[vertexIndex + 2] = c0;
                    newVertexColors[vertexIndex + 3] = c1;
                    _tmpText.UpdateVertexData();
                }

                currentCharacter = (currentCharacter + 1) % characterCount;
                yield return(new WaitForSeconds(0.05f));
            }
        }
Esempio n. 26
0
        public void ResetCharacters(bool fadeout)
        {
            m_TextComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo = m_TextComponent.textInfo;

            Color32[] newVertexColors;

            int characterCount = textInfo.characterCount;

            for (int i = 0; i < characterCount; i++)
            {
                // Skip characters that are not visible
                if (!textInfo.characterInfo[i].isVisible)
                {
                    continue;
                }

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

                // Get the vertex colors of the mesh used by this text element (character or sprite).
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;

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

                // Get the current character's alpha value.
                byte alpha = fadeout ? (byte)initialColor.a : (byte)0;

                newVertexColors[vertexIndex + 0].a = alpha;
                newVertexColors[vertexIndex + 1].a = alpha;
                newVertexColors[vertexIndex + 2].a = alpha;
                newVertexColors[vertexIndex + 3].a = alpha;

                m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }
        }
Esempio n. 27
0
    public void SetTextColor(Color32 color)
    {
        dialogueText.ForceMeshUpdate(true);

        for (int j = 0; j < dialogueText.textInfo.wordCount - 1; j++)
        {
            TMP_WordInfo info = dialogueText.textInfo.wordInfo[j];
            for (int i = 0; i < info.characterCount; ++i)
            {
                int charIndex   = info.firstCharacterIndex + i;
                int meshIndex   = dialogueText.textInfo.characterInfo[charIndex].materialReferenceIndex;
                int vertexIndex = dialogueText.textInfo.characterInfo[charIndex].vertexIndex;

                Color32[] vertexColors = dialogueText.textInfo.meshInfo[meshIndex].colors32;
                vertexColors[vertexIndex + 0] = newColor;
                vertexColors[vertexIndex + 1] = newColor;
                vertexColors[vertexIndex + 2] = newColor;
                vertexColors[vertexIndex + 3] = newColor;
            }

            dialogueText.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
        }
    }
Esempio n. 28
0
    private IEnumerator HighlighWords(TMP_Text definitionsText)
    {
        yield return(null);

        textInfoCache = definitionsText.textInfo;

        if (definitionsText.text.Length > 0)
        {
            textInfoCache = definitionsText.textInfo;


            for (int i = 0; i < textInfoCache.wordCount; i++)
            {
                wordInfoCache = textInfoCache.wordInfo[i];

                if (wordInfoCache.GetWord().Length > 2 && !DatabaseManager.ActiveDatabase.ContainsKey(wordInfoCache.GetWord().ToLower()))
                {
                    yield return(new WaitForSeconds(0.05f));

                    // Iterate through each of the characters of the word.
                    for (int j = 0; j < wordInfoCache.characterCount; ++j)
                    {
                        int charIndex   = wordInfoCache.firstCharacterIndex + j;
                        int meshIndex   = definitionsText.textInfo.characterInfo[charIndex].materialReferenceIndex;
                        int vertexIndex = definitionsText.textInfo.characterInfo[charIndex].vertexIndex;

                        Color32[] vertexColors = definitionsText.textInfo.meshInfo[meshIndex].colors32;
                        vertexColors[vertexIndex + 0] = highlightColor;
                        vertexColors[vertexIndex + 1] = highlightColor;
                        vertexColors[vertexIndex + 2] = highlightColor;
                        vertexColors[vertexIndex + 3] = highlightColor;
                    }
                }
                definitionsText.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
            }
        }
    }
Esempio n. 29
0
    private void AnimateVertexColors(int index)
    {
        TMP_TextInfo textInfo = textMeshDisplay.textInfo;

        Color32[] newVertexColors;
        Color32   c0 = textMeshDisplay.color;

        int materialIndex = textInfo.characterInfo[index].materialReferenceIndex;

        newVertexColors = textInfo.meshInfo[materialIndex].colors32;
        int vertexIndex = textInfo.characterInfo[index].vertexIndex;

        if (textInfo.characterInfo[index].isVisible)
        {
            c0 = Color.red;

            newVertexColors[vertexIndex + 0] = c0;
            newVertexColors[vertexIndex + 1] = c0;
            newVertexColors[vertexIndex + 2] = c0;
            newVertexColors[vertexIndex + 3] = c0;

            textMeshDisplay.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
        }
    }
Esempio n. 30
0
        /// <summary>
        /// This sets the alpha of a character, it's used for the ticker effect
        /// </summary>
        /// <param name="textInfo"></param>
        /// <param name="index"></param>
        /// <param name="value"></param>
        private void Alpha(TMP_TextInfo textInfo, int index, byte value)
        {
            if (!textInfo.characterInfo[index].isVisible)
            {
                return;
            }

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

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

            // Get the vertex colors of the mesh used by this text element (character or sprite).
            var newVertexColors = textInfo.meshInfo[materialIndex].colors32;

            for (byte corner = 0; corner < 4; corner++)
            {
                newVertexColors[vertexIndex + corner].a = value;
            }

            // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
            TMProText.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
        }