Changing subtitle color for new languages
Re: Changing subtitle color for new languages
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?
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
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
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
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
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:
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
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
Yes. It doesn't show any error. I also checked the speaker by:
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
Debug.Log(subtitle.speakerInfo.transform.name);
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
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
I also used this script on the character GameObjects:
ExampleNpcScript.cs
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;
}
}
ExampleNpcScript.cs
Code: Select all
using UnityEngine;
public class ExampleNpcScript : MonoBehaviour
{
public Color color = Color.white;
}
Re: Changing subtitle color for new languages
Thanks a million Tony. Finally it works! : )
Re: Changing subtitle color for new languages
Whew! Thanks for your patience.