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

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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().)
Post Reply