static int ForceMeshUpdate(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1);
                obj.ForceMeshUpdate();
                return(0);
            }
            else if (count == 2)
            {
                TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1);
                bool arg0             = LuaDLL.luaL_checkboolean(L, 2);
                obj.ForceMeshUpdate(arg0);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshPro.ForceMeshUpdate"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 2
0
        public void Parsing_TextInfo_WordWrapDisabled(int sourceTextIndex, int characterCount, int spaceCount, int wordCount, int lineCount)
        {
            m_TextComponent.text = testStrings[sourceTextIndex];
            m_TextComponent.enableWordWrapping = false;
            m_TextComponent.alignment          = TextAlignmentOptions.TopLeft;

            // Size the RectTransform
            m_TextComponent.rectTransform.sizeDelta = new Vector2(50, 5);

            // Force text generation to populate the TextInfo data structure.
            m_TextComponent.ForceMeshUpdate();

            Assert.AreEqual(m_TextComponent.textInfo.characterCount, characterCount);
            Assert.AreEqual(m_TextComponent.textInfo.spaceCount, spaceCount);
            Assert.AreEqual(m_TextComponent.textInfo.wordCount, wordCount);
            Assert.AreEqual(m_TextComponent.textInfo.lineCount, lineCount);
        }
Esempio n. 3
0
 public void ApplyTagEffects()
 {
     // Applies the effects of parsedTags on the text
     Debug.Log("ApplyingTagEffects");
     lineText = GetComponent <TMPro.TextMeshPro>();
     lineText.ForceMeshUpdate();
     foreach (var tag in parsedTags)
     {
         Debug.Log("Applying " + tag.tag_name + " with parameter " + tag.tag_param + " to text at index " + tag.startIndex + " with length " + tag.length);
         var clonedTagRunner = customTags[tag.tag_name].clone();
         clones.Add(clonedTagRunner);
         StartCoroutine(clones[clones.Count - 1].applyToText(lineText, tag.startIndex, tag.length, tag.tag_param));
     }
 }
Esempio n. 4
0
 public bool GenerateTextMesh(string text, int fontSize, Color colour, ref Mesh mesh, ref Material material)
 {
     // Generate a mesh using TextMeshPro.
     TMPro.TextMeshPro tmp = GetComponent <TMPro.TextMeshPro>();
     if (tmp != null)
     {
         tmp.fontSize = fontSize;
         tmp.text     = text;
         tmp.ForceMeshUpdate();
         mesh     = Mesh.Instantiate(tmp.mesh);
         material = new Material(tmp.fontMaterial);
         material.SetColor("_FaceColor", colour);
         // material.SetColor("_OutlineColor", colour);
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
 void Start()
 {
     text = GetComponent <TMPro.TextMeshPro>();
     text.ForceMeshUpdate();
     text.UpdateFontAsset();
 }
Esempio n. 6
0
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        lineText.gameObject.SetActive(false);
        lineText.gameObject.SetActive(true);
        // Reset text
        customTagHandler.StopAllCoroutines();
        customTagHandler.clearClones();
        prevColors.Clear();
        lineText.SetText(customTagHandler.ParseForCustomTags(YarnRTFToTMP(line.text)));
        lineText.ForceMeshUpdate();
        customTagHandler.ApplyTagEffects();

        // Set up teletype by setting alpha to 0
        TMPro.TMP_Text     m_TextComponent = lineText.GetComponent <TMPro.TMP_Text>();
        TMPro.TMP_TextInfo textInfo        = m_TextComponent.textInfo;
        while (textInfo.characterCount == 0)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        Color32[] newVertexColors;
        for (int currentCharacter = 0; currentCharacter < textInfo.characterCount; currentCharacter++)
        {
            int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
            newVertexColors = textInfo.meshInfo[materialIndex].colors32;
            int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
            // Save prev color
            if (textInfo.characterInfo[currentCharacter].isVisible)
            {
                for (int j = 0; j < 4; j++)
                {
                    prevColors.Add(textInfo.meshInfo[materialIndex].colors32[vertexIndex + j]);
                }
            }
            else
            {
                for (int j = 0; j < 4; j++)
                {
                    prevColors.Add(new Color32(0, 0, 0, 0));
                }
            }
            // Set color to transparent
            if (textInfo.characterInfo[currentCharacter].isVisible)
            {
                for (int j = 0; j < 4; j++)
                {
                    newVertexColors[vertexIndex + j] = new Color32(textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].r, textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].g, textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].b, 0);
                }
                m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
            }
        }

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            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)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        newVertexColors[vertexIndex + j] = prevColors[4 * i + j];
                    }
                    m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
                }
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the entire line immediately if textSpeed <= 0
            for (int currentCharacter = 0; currentCharacter < textInfo.characterCount; currentCharacter++)
            {
                int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
                // Set color back to the color it is supposed to be
                if (textInfo.characterInfo[currentCharacter].isVisible)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        newVertexColors[vertexIndex + j] = prevColors[4 * currentCharacter + j];
                    }
                    m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
                }
            }
        }

        // Reset custom tag runner
        customTagHandler.ClearParsedTags();

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for trigger press
        while (gameManager.LH_Trigger == false && gameManager.RH_Trigger == false)
        {
            yield return(null);
        }

        // Avoid skipping lines if textSpeed == 0
        yield return(new WaitForEndOfFrame());

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }