Changing subtitle color for new languages

Announcements, support questions, and discussion for the Dialogue System.
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post 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?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

Did you assign the panels to the Standard Dialogue UI's Subtitle Panels list and the Default NPC/PC Subtitle Panels?
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post 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!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post 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.
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post 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;
        }
    }
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post 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.
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post 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;
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post 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;
}
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post by fanaei »

Thanks a million Tony. Finally it works! : )
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

Whew! ;-) Thanks for your patience.
Post Reply