예제 #1
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);

            data.hooks.textData.m_TextComponent.ForceMeshUpdate();
            int totalVisibleCharacters = data.hooks.textData.m_TextComponent.textInfo.characterCount; // Get # of Visible Character in text object
            int visibleCount           = 0;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            while ((Time.time - initialTime) / data.duration < 1)
            {
                yValue       = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));
                visibleCount = (int)(yValue * totalVisibleCharacters);
                data.hooks.textData.m_TextComponent.maxVisibleCharacters = visibleCount;

                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                data.hooks.textData.m_TextComponent.maxVisibleCharacters = totalVisibleCharacters;
            }
        }
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            float size        = 0;
            float initialSize = 0f;
            float finalSize   = data.hooks.textData.m_TextComponent.fontSize;

            data.hooks.textData.m_TextComponent.fontSize = 0f;

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                size = initialSize + yValue * (finalSize - initialSize);

                data.hooks.textData.m_TextComponent.fontSize = size;
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                data.hooks.textData.m_TextComponent.fontSize = finalSize;
            }
        }
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();

            int     finalAlpha;
            Color32 finalColor   = data.hooks.textData.m_TextComponent.color;
            int     initialAlpha = finalColor.a;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                finalAlpha   = (int)(initialAlpha + yValue * (wantedAlpha - initialAlpha));
                finalColor.a = (byte)finalAlpha;

                data.hooks.textData.m_TextComponent.color = finalColor;
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                finalColor.a = (byte)wantedAlpha;
                data.hooks.textData.m_TextComponent.color = finalColor;
            }
        }
예제 #4
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();
            data.curve.preWrapMode  = WrapMode.Loop;
            data.curve.postWrapMode = WrapMode.Loop;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            Vector3 localScale = data.hooks.textData.rectTransform.localScale;
            Vector3 finalScale = data.hooks.textData.rectTransform.localScale * 1.5f;
            Vector3 stepScale;

            while (((Time.time - initialTime) / data.duration) < 1 || keepAnimating)
            {
                yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                stepScale = localScale + yValue * (finalScale - localScale);

                data.hooks.textData.rectTransform.localScale = stepScale;
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                data.hooks.textData.rectTransform.localScale = localScale;
            }
        }
 public IEnumerator SetEffects(AbstractTextEffect.TextEffectEnum effect, TextEffectData data)
 {
     if (!data.hooks.text)
     {
         throw new MissingComponentException("Hooks text attribute not found.");
     }
     return(EffectsManager.Instance.Play(effect, data));
 }
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            Matrix4x4 matrix;

            Vector3[] vertices;
            int       loopCount = 0;

            float initialTime = Time.time;

            float[] vertexAnimAngleRanges = new float[1024];
            float[] vertexAnimSpeeds      = new float[1024];
            for (int i = 0; i < 1024; i++)
            {
                vertexAnimAngleRanges[i] = Random.Range(1f, 3f) + Random.Range(3f, 8f) * data.intensity;
                vertexAnimSpeeds[i]      = Random.Range(0.2f, 0.5f) + Random.Range(0.5f, 3.0f) * data.intensity;
            }

            int characterCount = data.hooks.textData.m_TextComponent.textInfo.characterCount;

            while (((Time.time - initialTime) / data.duration) < 1 || keepAnimating)
            {
                data.hooks.textData.m_TextComponent.ForceMeshUpdate();
                vertices = data.hooks.textData.m_TextComponent.mesh.vertices;

                for (int i = 0; i < characterCount; i++)
                {
                    var charInfo = data.hooks.textData.m_TextComponent.textInfo.characterInfo[i];

                    if (!charInfo.isVisible)
                    {
                        continue;
                    }

                    int vertexIndex = charInfo.vertexIndex;

                    Vector3 charMidTopLine = new Vector3((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, charInfo.topRight.y);

                    var vertAnimAngle = Mathf.SmoothStep(-vertexAnimAngleRanges[i], vertexAnimAngleRanges[i], Mathf.PingPong(loopCount / 25f * vertexAnimSpeeds[i], 1f));
                    matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, vertAnimAngle), Vector3.one);
                    ApplyMatrix(vertices, vertices, matrix, charMidTopLine, vertexIndex);
                }

                loopCount++;

                for (int i = 0; i < data.hooks.textData.m_TextComponent.textInfo.meshInfo.Length; i++)
                {
                    data.hooks.textData.m_TextComponent.textInfo.meshInfo[i].mesh.vertices = vertices;
                    data.hooks.textData.m_TextComponent.UpdateGeometry(data.hooks.textData.m_TextComponent.textInfo.meshInfo[i].mesh, i);
                }
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                data.hooks.textData.m_TextComponent.ForceMeshUpdate();
            }
        }
예제 #7
0
        public IEnumerator Play(AbstractTextEffect.TextEffectEnum effect, TextEffectData data)
        {
            if (!text.ContainsKey(effect))
            {
                throw new KeyNotFoundException(effect.ToString() + " not found.");
            }

            IEnumerator coroutine = text[effect].Run(data);

            Play(coroutine);
            return(coroutine);
        }
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            Vector3 finalScale = data.hooks.textData.rectTransform.localScale;

            Vector3 zeroScale = Vector3.zero;

            data.hooks.textData.rectTransform.localScale = zeroScale;
            Vector3 localScale = data.hooks.textData.rectTransform.localScale;

            float initialScaleX = localScale.x;
            float initialScaleY = localScale.y;

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                if (x)
                {
                    finalScale.x = initialScaleX + yValue * (wantedScaleX - initialScaleX);
                }
                if (y)
                {
                    finalScale.y = initialScaleY + yValue * (wantedScaleY - initialScaleY);
                }

                data.hooks.textData.rectTransform.localScale = finalScale;
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                if (x)
                {
                    finalScale.x = wantedScaleX;
                }
                if (y)
                {
                    finalScale.y = wantedScaleY;
                }
                data.hooks.textData.rectTransform.localScale = finalScale;
            }
        }
예제 #9
0
        protected virtual void Clean(TextEffectData data)
        {
            if (!data.hooks.textData.m_TextComponent.IsActive())
            {
                return;
            }
            data.hooks.text.enableAutoSizing = true;
            data.hooks.textData.initialColor = data.hooks.textData.m_TextComponent.color;

            if (data.show)
            {
                data.hooks.textData.ResetCharacters(true);
                data.hooks.textData.ResetColor(true, true);
                data.hooks.textData.ResetRectTransform(true, true, true);
                data.hooks.textData.ResetCharacterCount();
            }
        }
예제 #10
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();

            Color32 initialColor = data.hooks.textData.m_TextComponent.color, finalColor = new Color32();
            int     red, green, blue, alpha;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            Color blushColor = DefaultData.Instance.GetBlushColor();

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                red   = (int)(initialColor.r + yValue * (((byte)(blushColor.r * 255)) - initialColor.r));
                green = (int)(initialColor.g + yValue * (((byte)(blushColor.g * 255)) - initialColor.g));
                blue  = (int)(initialColor.b + yValue * (((byte)(blushColor.b * 255)) - initialColor.b));
                alpha = (int)(initialColor.a + yValue * (((byte)(blushColor.a * 255)) - initialColor.a));

                finalColor.r = (byte)red;
                finalColor.g = (byte)green;
                finalColor.b = (byte)blue;
                finalColor.a = (byte)alpha;

                data.hooks.textData.m_TextComponent.color = finalColor;
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                data.hooks.textData.m_TextComponent.color = blushColor;
            }
        }
예제 #11
0
 protected override void Clean(TextEffectData data)
 {
     base.Clean(data);
     data.hooks.textData.ResetCharacterCount();
 }
예제 #12
0
 public override IEnumerator Run(TextEffectData data)
 {
     Clean(data);
     yield break;
 }
예제 #13
0
 public abstract IEnumerator Run(TextEffectData data);
예제 #14
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();
            Keyframe lastframe;
            float    lastKeyTime   = 0f;
            bool     keepAnimating = false;

            if (data.curve != null)
            {
                data.curve.preWrapMode  = WrapMode.Loop;
                data.curve.postWrapMode = WrapMode.Loop;
                lastframe   = data.curve[data.curve.length - 1];
                lastKeyTime = lastframe.time;
            }

            float initialTime = Time.time;
            float range;

            TMP_TextInfo textInfo = data.hooks.textData.m_TextComponent.textInfo;

            TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
            Matrix4x4      matrix;

            data.hooks.textData.hasTextChanged = true;

            while (((Time.time - initialTime) / data.duration) < 1 || keepAnimating)
            {
                if (data.hooks.textData.hasTextChanged)
                {
                    cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
                    data.hooks.textData.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;
                }

                int lineCount = textInfo.lineCount;
                range = Random.Range(-0.25f, 0.25f) + Random.Range(-1.25f, 1.25f) * data.intensity;

                // Iterate through each line of the text.
                for (int i = 0; i < lineCount; i++)
                {
                    int first = textInfo.lineInfo[i].firstCharacterIndex;
                    int last  = textInfo.lineInfo[i].lastCharacterIndex;

                    // Determine the center of each line
                    Vector3    centerOfLine = (textInfo.characterInfo[first].bottomLeft + textInfo.characterInfo[last].topRight) / 2;
                    Quaternion rotation     = Quaternion.Euler(0, 0, range);

                    // Iterate through each character of the line.
                    for (int j = first; j <= last; j++)
                    {
                        // Skip characters that are not visible and thus have no geometry to manipulate.
                        if (!textInfo.characterInfo[j].isVisible)
                        {
                            continue;
                        }

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

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

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

                        if (!characters)
                        {
                            // Setup the matrix rotation.
                            matrix = Matrix4x4.TRS(Vector3.one, rotation, Vector3.one);
                            ApplyMatrix(sourceVertices, copyOfVertices, matrix, centerOfLine, vertexIndex);
                        }
                        else
                        {
                            Vector3 charMidBasline = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;
                            matrix = Matrix4x4.TRS(Vector3.one, rotation, Vector3.one);
                            ApplyMatrix(sourceVertices, copyOfVertices, matrix, charMidBasline, vertexIndex);
                        }
                    }

                    //Change with intensity
                    yield return(new WaitForSeconds(Time.deltaTime));
                }

                for (int i = 0; i < textInfo.meshInfo.Length; i++)
                {
                    textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
                    data.hooks.textData.m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
                }

                yield return(new WaitForSeconds(Time.deltaTime));
            }
        }
예제 #15
0
 protected override void Clean(TextEffectData data)
 {
     base.Clean(data);
     data.hooks.textData.ResetRectTransform(true, false, false);
 }
예제 #16
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            // Need to force the text object to be generated so we have valid data to work with right from the start.
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo = data.hooks.textData.m_TextComponent.textInfo;

            Color32[] newVertexColors;

            int characterCount = textInfo.characterCount;

            Color32 finalColor = data.hooks.textData.m_TextComponent.color;
            int     initialAlpha;
            byte    finalAlpha;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                for (int i = 0; i < characterCount; i++)
                {
                    initialAlpha = data.hooks.textData.m_TextComponent.textInfo.characterInfo[i].color.a;
                    // 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;


                    yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration));

                    finalAlpha = (byte)(initialAlpha + yValue * (wantedAlpha - initialAlpha));
                    // Set new alpha values.
                    newVertexColors[vertexIndex + 0].a = finalAlpha;
                    newVertexColors[vertexIndex + 1].a = finalAlpha;
                    newVertexColors[vertexIndex + 2].a = finalAlpha;
                    newVertexColors[vertexIndex + 3].a = finalAlpha;

                    // Upload the changed vertex colors to the Mesh.
                    data.hooks.textData.m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);

                    yield return(new WaitForSeconds(Time.deltaTime));
                }
            }

            if (DefaultData.Instance.forceTextUpdate)
            {
                for (int i = 0; i < characterCount; i++)
                {
                    // 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;

                    finalAlpha = (byte)wantedAlpha;
                    // Set new alpha values.
                    newVertexColors[vertexIndex + 0].a = finalAlpha;
                    newVertexColors[vertexIndex + 1].a = finalAlpha;
                    newVertexColors[vertexIndex + 2].a = finalAlpha;
                    newVertexColors[vertexIndex + 3].a = finalAlpha;
                    data.hooks.textData.m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
                }
            }
        }
예제 #17
0
 protected override void Clean(TextEffectData data)
 {
     base.Clean(data);
 }
예제 #18
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.hooks.textData.m_TextComponent.ForceMeshUpdate();
            Keyframe lastframe;
            float    lastKeyTime = 0f;

            if (data.curve != null)
            {
                data.curve.preWrapMode  = WrapMode.Loop;
                data.curve.postWrapMode = WrapMode.Loop;
                lastframe   = data.curve[data.curve.length - 1];
                lastKeyTime = lastframe.time;
            }

            float initialTime = Time.time;
            float rangeX, rangeY;

            TMP_TextInfo textInfo = data.hooks.textData.m_TextComponent.textInfo;

            TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
            Matrix4x4      matrix;

            data.hooks.textData.hasTextChanged = true;

            while (((Time.time - initialTime) / data.duration) < 1 || keepAnimating)
            {
                if (data.hooks.textData.hasTextChanged)
                {
                    cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
                    data.hooks.textData.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;
                }

                int lineCount = textInfo.lineCount;

                if (random)
                {
                    rangeX = Random.Range(-0.25f, 0.25f) + Random.Range(-1.25f, 1.25f) * data.intensity;
                    rangeY = Random.Range(-0.25f, 0.25f) + Random.Range(-1.25f, 1.25f) * data.intensity;
                }
                else
                {
                    rangeX = rangeY = Random.Range(-0.25f, 0.25f) + Mathf.Clamp(data.curve.Evaluate((Time.time - initialTime) * lastKeyTime / data.duration), -1.25f, 1.25f) * data.intensity;
                }

                // Iterate through each line of the text.
                for (int i = 0; i < lineCount; i++)
                {
                    int     first        = textInfo.lineInfo[i].firstCharacterIndex;
                    int     last         = textInfo.lineInfo[i].lastCharacterIndex;
                    Vector3 centerOfLine = (textInfo.characterInfo[first].bottomLeft + textInfo.characterInfo[last].topRight) / 2;

                    for (int j = first; j <= last; j++)
                    {
                        if (!textInfo.characterInfo[j].isVisible)
                        {
                            continue;
                        }

                        int       materialIndex  = textInfo.characterInfo[j].materialReferenceIndex;
                        int       vertexIndex    = textInfo.characterInfo[j].vertexIndex;
                        Vector3[] sourceVertices = cachedMeshInfo[materialIndex].vertices;
                        Vector3[] copyOfVertices = textInfo.meshInfo[materialIndex].vertices;
                        matrix = Matrix4x4.TRS(new Vector3(rangeX, rangeY, 0.0f), Quaternion.identity, Vector3.one);

                        ApplyMatrix(sourceVertices, copyOfVertices, matrix, centerOfLine, vertexIndex);
                    }

                    //Change with intensity
                    yield return(new WaitForSeconds(Time.deltaTime));
                }

                for (int i = 0; i < textInfo.meshInfo.Length; i++)
                {
                    textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
                    data.hooks.textData.m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
                }

                yield return(new WaitForSeconds(Time.deltaTime));
            }
        }
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            TMP_TextInfo textInfo = data.hooks.textData.m_TextComponent.textInfo;

            Color32[] newVertexColors;
            Color32   finalColor = data.hooks.textData.m_TextComponent.color;
            float     initialAlpha;
            int       alpha;

            int characterCount = textInfo.characterCount;

            float    initialCharTime;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;
            float    yValue;

            for (int i = 0; i < characterCount; i++)
            {
                initialCharTime = Time.time;
                initialAlpha    = data.hooks.textData.m_TextComponent.textInfo.characterInfo[i].color.a;

                // 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;

                while ((((Time.time - initialCharTime) * characterCount / data.duration) < 1))
                {
                    yValue = Mathf.Clamp01(data.curve.Evaluate((Time.time - initialCharTime) * lastKeyTime * characterCount / data.duration));

                    alpha = (int)(initialAlpha + yValue * (wantedAlpha - initialAlpha));

                    finalColor.a = (byte)alpha;

                    newVertexColors[vertexIndex + 0] = finalColor;
                    newVertexColors[vertexIndex + 1] = finalColor;
                    newVertexColors[vertexIndex + 2] = finalColor;
                    newVertexColors[vertexIndex + 3] = finalColor;
                    data.hooks.textData.m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
                    yield return(new WaitForSeconds(Time.deltaTime));
                }

                if (DefaultData.Instance.forceTextUpdate)
                {
                    finalColor.a = (byte)wantedAlpha;
                    newVertexColors[vertexIndex + 0] = finalColor;
                    newVertexColors[vertexIndex + 1] = finalColor;
                    newVertexColors[vertexIndex + 2] = finalColor;
                    newVertexColors[vertexIndex + 3] = finalColor;
                    data.hooks.textData.m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
                }
            }
        }
 protected override void Clean(TextEffectData data)
 {
     base.Clean(data);
     data.hooks.text.enableAutoSizing = false;
 }
예제 #21
0
        public override IEnumerator Run(TextEffectData data)
        {
            Clean(data);
            data.curve.preWrapMode  = WrapMode.Clamp;
            data.curve.postWrapMode = WrapMode.Clamp;

            Vector3[] vertices;
            Matrix4x4 matrix;

            data.hooks.textData.m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
            float CurveScale = data.intensity * 10;

            float    initialTime = Time.time;
            Keyframe lastframe   = data.curve[data.curve.length - 1];
            float    lastKeyTime = lastframe.time;

            while (((Time.time - initialTime) / data.duration) < 1)
            {
                data.hooks.textData.m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.

                TMP_TextInfo textInfo       = data.hooks.textData.m_TextComponent.textInfo;
                int          characterCount = textInfo.characterCount;

                if (characterCount == 0)
                {
                    continue;
                }

                float boundsMinX = data.hooks.textData.m_TextComponent.bounds.min.x;  //textInfo.meshInfo[0].mesh.bounds.min.x;
                float boundsMaxX = data.hooks.textData.m_TextComponent.bounds.max.x;  //textInfo.meshInfo[0].mesh.bounds.max.x;

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

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

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

                    vertices = textInfo.meshInfo[materialIndex].vertices;

                    // Compute the baseline mid point for each character
                    Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);

                    // Compute the angle of rotation for each character based on the animation curve
                    float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
                    float x1 = x0 + 0.0001f;
                    float y0 = data.curve.Evaluate(x0) * CurveScale;
                    float y1 = data.curve.Evaluate(x1) * CurveScale;

                    Vector3 horizontal = new Vector3(1, 0, 0);
                    Vector3 tangent    = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);

                    float   dot   = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
                    Vector3 cross = Vector3.Cross(horizontal, tangent);
                    float   angle = cross.z > 0 ? dot : 360 - dot;

                    matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);

                    // Apply offset to adjust our pivot point.
                    ApplyMatrix(vertices, vertices, matrix, offsetToMidBaseline, vertexIndex);
                }
                // Upload the mesh with the revised information
                data.hooks.textData.m_TextComponent.UpdateVertexData();
                yield return(new WaitForSeconds(Time.deltaTime));
            }
        }
예제 #22
0
 protected override void Clean(TextEffectData data)
 {
     base.Clean(data);
     data.hooks.textData.ResetColor(true, false);
 }