Пример #1
0
    public void SetTextColor(Color32 color, int[] wordIndexes)
    {
        dialogueText.ForceMeshUpdate(true);

        for (int j = 0; j < wordIndexes.Length; j++)
        {
            TMP_WordInfo info = dialogueText.textInfo.wordInfo[wordIndexes[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] = color;
                vertexColors[vertexIndex + 1] = color;
                vertexColors[vertexIndex + 2] = color;
                vertexColors[vertexIndex + 3] = color;
            }
            dialogueText.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
        }
    }
Пример #2
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);
        }
    }