How to use Dialogue System on buttons and texts?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
DryreL
Posts: 29
Joined: Sat Dec 26, 2020 1:58 pm

How to use Dialogue System on buttons and texts?

Post by DryreL »

Hello, I want to use this tool on all buttons and texts because it supports multiple languages. In this way, when the language changes in the game, not only the subtitles but also the language of the main menu and esc menu will be changed. How can I do that? Thank you.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to use Dialogue System on buttons and texts?

Post by Tony Li »

Hi,

Add a LocalizeUI component to each text element (UI Text, TextMeshProUGUI, Dropdown, etc.).

Create a Text Table asset, add a field for each text element, and assign it to the Dialogue Manager's Localization Settings > Text Table field.

More info: Text Tables in the Dialogue System

You can also find a full manual on Text Tables in Plugins / Pixel Crushers / Common / Documentation.
User avatar
DryreL
Posts: 29
Joined: Sat Dec 26, 2020 1:58 pm

Re: How to use Dialogue System on buttons and texts?

Post by DryreL »

Hi,

I did what you said but I'm still having problem. Language change works on normal dialogues, that's good. However, it doesn't work on buttons. What did I wrong?

I added Text table to Dialogue System.

Image

Here's the text table:
Image

Text Table Fields:
Image

PLAY Button:
Image

Thank you.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to use Dialogue System on buttons and texts?

Post by Tony Li »

Hi,

How are you changing language? Are you using DialogueManager.SetLanguage()?
User avatar
DryreL
Posts: 29
Joined: Sat Dec 26, 2020 1:58 pm

Re: How to use Dialogue System on buttons and texts?

Post by DryreL »

Hello,

Yes, I used DialogueManager.SetLanguage().

Image

Does Text Table requires another code?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to use Dialogue System on buttons and texts?

Post by Tony Li »

No, that should work. Are your UI text GameObjects active? When you change languages, it does not currently update the text of inactive Localize UI components. The next version will do that.

Keep in mind that once you set a language, the Dialogue System will store that language choice in PlayerPrefs. So the next time you play, it will use the language choice stored in PlayerPrefs. To clear it, click the Dialogue Manager's Reset Language PlayerPrefs button. Or add a UI Localization Manager component to the Dialogue Manager and untick Save Language In PlayerPrefs to not save the player's choice.

Here is an example scene:

DS_LocalizeUIExample_2020-12-27.unitypackage

Instead of calling DialogueManager.SetLanguage(), I hooked up the buttons directly to the Dialogue Manager. But they're doing the same thing.
User avatar
DryreL
Posts: 29
Joined: Sat Dec 26, 2020 1:58 pm

Re: How to use Dialogue System on buttons and texts?

Post by DryreL »

Hello,

I forgot the add Dialogue Manager in main menu hiearchy. I added it and now it works fine! Thank you.

But I have 2 dialogue manager since they are in both scenes. It is marked as Singleton, so does the adding every scene Dialogue Manager causes any problem? Because I'm accessing this gameobject via button onClick() event, if it was only main menu scene, I cannot drag and drop to scene1's button. Any idea?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to use Dialogue System on buttons and texts?

Post by Tony Li »

Hi,

Having a Dialogue Manager in each scene is fine, and is the easiest way to be able to playtest individual scenes.

Since it's a singleton, when you change from scene 1 to scene 2, the Dialogue Manager from scene 1 will survive into scene 2 and replace the Dialogue Manager that was in scene 2.

This means you shouldn't connect UnityEvents directly to the Dialogue Manager GameObject, since it could be replaced by a different Dialogue Manager during scene changes. The only exception is if the UI Button is also configured to survive scene changes, such as if it's also a child of the Dialogue Manager GameObject.

Instead, add a tiny script to the UI Button. For example, you can add the script below to the UI Button. It will automatically add an OnClick() event at runtime, so you don't even need to set up OnClick().

SetLanguageButton.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(UnityEngine.UI.Button))]
public class SetLanguageButton : MonoBehaviour
{
    public string languageCode;
    private void Start()
    {
        GetComponent<UnityEngine.UI.Button>().onClick.AddListener(() => { DialogueManager.SetLanguage(languageCode); });
    }
}
User avatar
DryreL
Posts: 29
Joined: Sat Dec 26, 2020 1:58 pm

Re: How to use Dialogue System on buttons and texts?

Post by DryreL »

Thank you. I'll let you know if I encounter any problem.
Post Reply