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

Changing subtitle color for new languages

Post by fanaei »

Hi
I'm using TextMeshPro and added Farsi language (it's an rtl language). When I change the subtitle color from Dialogue Actor component. It changes if it's English. But when I use Farsi, it doesn't change! Do you know that what's the problem?
User avatar
Tony Li
Posts: 20789
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

Hi,

Are you using the Dialogue System's TextMeshProTypewriterEffect?

When you change the subtitle color, the Dialogue Actor adds rich text codes to the beginning and end of the text. Example:

<color=#00ffffff>This is a test.</color>

Are you seeing invalid characters? If so, TextMesh Pro may be inverting everything, including the rich text codes:

>roloc/<.tset a si sihT>ffffff00#=roloc<

I'm not sure how TextMesh Pro handles rich text codes and RTL. You may need to turn off the Dialogue Actor's Set Subtitle Color checkbox. Instead, add a script to the NPC with an OnConversationLine method that sets the TextMeshProUGUI's color directly. Example:

Code: Select all

public class TMPActorColor : MonoBehaviour
{
    public Color actorColor;
    
    void OnConversationLine(Subtitle subtitle)
    {
        if (subtitle.speakerInfo.transform == this.transform)
        {
            var uiElements = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements;
            var panel = subtitle.speakerInfo.isNPC ? uiElements.defaultNPCSubtitlePanel : uiElements.defaultPCSubtitlePanel;
            panel.subtitleText.textMeshProUGUI.color = actorColor;
        }
    }
}
(EDIT: Fixed script to set color only for the script's owner and for PC vs. NPC.)
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post by fanaei »

Yes. I'm using Dialogue System's TextMeshProTypewriterEffect.
I tested your code but it changes color for both player and NPC. :(
User avatar
Tony Li
Posts: 20789
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

I forgot a line in the script. I just updated it above.
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post by fanaei »

I added your edited script to both Player and Npc, but texts of dialogues for both of them changes to Player's color and NPC texts gets the player color.
If I add the script only to NPC, it doesn't change the color at all.
If I add it only to player, it changes the color for both player and NPC
Last edited by fanaei on Wed Jan 29, 2020 9:58 am, edited 1 time in total.
User avatar
Tony Li
Posts: 20789
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

Please try the updated script above. I had originally intended it only as a rough example. I updated it to handle PC and NPC (assuming you're using the default subtitle panels for them), so you should be able to use it in your project as-is.
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post by fanaei »

Your updated script only works on Player and changes the color for both PC and NPC to the same color.
But if I use this below code that your wrote first on my NPC and set subtitle color for Player on Dialogue Actor component. The player uses the main ui color and NPC uses your first script color:

Code: Select all

var tmp = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements.defaultNPCSubtitlePanel.subtitleText.textMeshProUGUI;
        tmp.color = actorColor;
User avatar
Tony Li
Posts: 20789
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

Is it working the way you need now?
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: Changing subtitle color for new languages

Post by fanaei »

Yes Tony it works somehow now. Thank you :)
User avatar
Tony Li
Posts: 20789
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing subtitle color for new languages

Post by Tony Li »

I'm glad it's working now. :-)
Post Reply