Hello,
I was wondering if I can switch languages using Sequence or Lua script in a conversation node?
My requirement is to change the language while responding.
Thank you for your kind assistance
Switch Language with Conversation Node
Re: Switch Language with Conversation Node
Hi,
You could register a C# method with Lua and use it in the Script field. Example:
Add a script with this method to the Dialogue Manager. Then use SetLanguage("your-language") in a dialogue entry's Script field.
You could register a C# method with Lua and use it in the Script field. Example:
Code: Select all
private void Start()
{
Lua.RegisterFunction("SetLanguage", DialogueManager.instance, SymbolExtensions.GetMethodInfo(() => DialogueManager.instance.SetLanguage("")));
}
Re: Switch Language with Conversation Node
It works flawlessly! Thank you very much!
Here is my code:
References:
Hope it helps somebody else
Here is my code:
Code: Select all
public class LuaRegister : MonoBehaviour
{
/// <summary>
/// Unity Start
/// </summary>
private void Start()
{
Lua.RegisterFunction(nameof(SetLanguage), this, SymbolExtensions.GetMethodInfo(() => SetLanguage(string.Empty)));
}
/// <summary>
/// Switch Language
/// </summary>
/// <param name="_newLanguage"> New Language </param>
private void SetLanguage(string _newLanguage)
{
// Update Language
DialogueManager.instance.SetLanguage(_newLanguage);
// Update Response
DialogueManager.UpdateResponses();
// Change actors' name
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);
}
}
}
Hope it helps somebody else
Re: Switch Language with Conversation Node
Thanks for sharing!