Page 1 of 1

[HOWTO] How To: Update Currently-Displayed Text When Changing Language

Posted: Mon May 22, 2023 9:16 am
by Tony Li
When you change the Dialogue System's language, subtitle text and response menu text will use the new language in the next subtitle or menu. Character names will use the new language when you start a new conversation. If you want to update them immediately, use code like the example below:

Code: Select all

public void SetLanguage(string newLanguage)
{
    DialogueManager.instance.SetLanguage(newLanguage);
    UpdateCharacterNames();
    UpdateSubtitleText();
    DialogueManager.UpdateResponses();
}

public void UpdateSubtitleText()
{
    var subtitle = DialogueManager.currentConversationState.subtitle;
    subtitle.formattedText.text = FormattedText.Parse(subtitle.dialogueEntry.currentDialogueText);
    DialogueManager.standardUISubtitlePanel.ShowSubtitle(subtitle);
    // (^ Alternatively you could just set the subtitle panel's subtitleText.text.)
}

public void UpdateCharacterNames()
{
    var conversation = DialogueManager.masterDatabase.GetConversation(DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID);
    var actorIDs = new HashSet<int>();
    conversation.dialogueEntries.ForEach(entry => actorIDs.Add(entry.ActorID));
    foreach (var actorID in actorIDs)
    {
        var characterInfo = DialogueManager.conversationModel.GetCharacterInfo(actorID);
        characterInfo.Name = PixelCrushers.DialogueSystem.CharacterInfo.GetLocalizedDisplayNameInDatabase(characterInfo.nameInDatabase);
    }
}
(Call this script's SetLanguage() method instead of DialogueManager.SetLanguage().)