Page 2 of 2

Re: Changing subtitle color for new languages

Posted: Fri Feb 07, 2020 1:13 pm
by fanaei
Tony, I have problem again!
I think the problem came from having one subtitle panel for both PC and NPC
I duplicated the panel. Now the colors are okay but the text doesn't fade out or gone when the text changes.
How can I solve this problem?

Re: Changing subtitle color for new languages

Posted: Fri Feb 07, 2020 1:42 pm
by Tony Li
Did you assign the panels to the Standard Dialogue UI's Subtitle Panels list and the Default NPC/PC Subtitle Panels?

Re: Changing subtitle color for new languages

Posted: Fri Feb 07, 2020 2:05 pm
by fanaei
The fading texts is okay now. But when I finish a dialogue and start the second dialogue, the NPC's color doesn't get its color and uses the NPC's color from previous dialogue!

Re: Changing subtitle color for new languages

Posted: Fri Feb 07, 2020 2:40 pm
by Tony Li
Did you add the script to the Dialogue Manager or to a specific character? Try adding it to the Dialogue Manager if that's not where it is now.

Re: Changing subtitle color for new languages

Posted: Sun Feb 09, 2020 12:46 pm
by fanaei
It works. But I can't have a different color for different NPCs.
I tried this code, But it doesn't work when I try to get the color from Npc script:

Code: Select all

    void OnConversationLine(Subtitle subtitle)
    {
        if (subtitle.speakerInfo.transform.GetComponent<NpcScript>()){
            var tmp = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements.defaultNPCSubtitlePanel.subtitleText.textMeshProUGUI;
            tmp.color = subtitle.speakerInfo.transform.GetComponent<NpcScript>().actorColor;
        }
    }

Re: Changing subtitle color for new languages

Posted: Sun Feb 09, 2020 12:53 pm
by Tony Li
Does it report an error? Or does it silently do nothing? If it does nothing, make sure the speaker GameObject is correct.

Re: Changing subtitle color for new languages

Posted: Sun Feb 09, 2020 12:56 pm
by fanaei
Yes. It doesn't show any error. I also checked the speaker by:

Code: Select all

Debug.Log(subtitle.speakerInfo.transform.name);
It shows the name of NPC but the color doesn't change.
I think if I be able to get the color before "OnConversatonLine" it will work.

When I use below code, The Npc's color, gets its color from PC color script!

Code: Select all

RTLTMPro.RTLTextMeshPro tmp = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements.defaultNPCSubtitlePanel.subtitleText.textMeshProUGUI;
            tmp.color = subtitle.speakerInfo.transform.GetComponent<NpcScript>().actorColor;

Re: Changing subtitle color for new languages

Posted: Sun Feb 09, 2020 3:51 pm
by Tony Li
I put together a test to identify the issue. While TextMesh Pro is recalculating it mesh, it doesn't register color changes. You need to wait until the end of frame. Here's an example:

DS_ActorColorTMPExample_2020-02-09.unitypackage

I used this script on the Dialogue Manager:

ExampleTMPActorColor.cs

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;
using TMPro;

public class ExampleTMPActorColor : MonoBehaviour
{
    public void OnConversationLine(Subtitle subtitle)
    {
        var uiElements = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements;
        var panel = subtitle.speakerInfo.isNPC ? uiElements.defaultNPCSubtitlePanel : uiElements.defaultPCSubtitlePanel;
        var npcScript = subtitle.speakerInfo.transform.GetComponent<ExampleNpcScript>();
        if (npcScript != null)
        {
            StartCoroutine(SetColor(panel.subtitleText.textMeshProUGUI, npcScript.color));
        }
    }

    IEnumerator SetColor(TextMeshProUGUI textMeshProUGUI, Color color)
    {
        yield return new WaitForEndOfFrame();
        textMeshProUGUI.color = color;
    }
}
I also used this script on the character GameObjects:

ExampleNpcScript.cs

Code: Select all

using UnityEngine;
public class ExampleNpcScript : MonoBehaviour
{
    public Color color = Color.white;
}

Re: Changing subtitle color for new languages

Posted: Mon Feb 10, 2020 9:23 am
by fanaei
Thanks a million Tony. Finally it works! : )

Re: Changing subtitle color for new languages

Posted: Mon Feb 10, 2020 9:30 am
by Tony Li
Whew! ;-) Thanks for your patience.