Page 1 of 2
Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 4:00 am
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?
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 8:45 am
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.)
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 9:05 am
by fanaei
Yes. I'm using Dialogue System's TextMeshProTypewriterEffect.
I tested your code but it changes color for both player and NPC.
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 9:10 am
by Tony Li
I forgot a line in the script. I just updated it above.
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 9:23 am
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
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 9:58 am
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.
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 10:06 am
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;
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 10:20 am
by Tony Li
Is it working the way you need now?
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 10:24 am
by fanaei
Yes Tony it works somehow now. Thank you
Re: Changing subtitle color for new languages
Posted: Wed Jan 29, 2020 12:31 pm
by Tony Li
I'm glad it's working now.