I have created a scene where I can click on a button and the next sting in the list will be displayed. So I wrote a script that creates a class to define my string array with its title and reference in the inspector. Then I simply inserted the string I needed into the inspector. Now we want to have our games in two different languages (German and English). Here I changed the string array to a LocalizedSting array. This way my text is localised and can be referenced to a traction table. After that I could no longer fill the required string via the Unity Inspector (see photo). It now displays “Use TextAreaDrawer with string”, previously I had empty boxes where I could enter my string.
Does anyone here know a solution so that I can insert the string again via the Inspector? To change the whole dynamic of reading this strings will be so much work.
I still have some issues with this. I have now set everything in my table. But when I change the language, the default language remains in place. I have not used any of the localization scripts. Which one do I need to use in this case?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
[System.Serializable ]
public class Infos
{
public LocalizedString title;
//[SerializeField] [TextArea]
//[TextArea(3,10)]
public LocalizedString[] sentences;
}
Trigger to start the dialogue with user:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InfosTrigger : MonoBehaviour
{
public Infos infos;
public void TriggerInfos()
{
FindObjectOfType<PopUpManager>().StartInfos(infos);
// FindObjectOfType<PopUpManager>().EndInfos(infos);
}
}
Manager for the dialogue:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Localization;
using UnityEngine.EventSystems;
public class PopUpManager : MonoBehaviour
{
// Start is called before the first frame update
public Text titleText;
public Text infoText;
//public Animator animator;
private Queue<string> sentences;
public bool close;
//public EventSystem eventSystemMainCanvas;
void Start()
{
//Initilisation.
sentences = new Queue<string>();
close = false;
}
public void StartInfos(Infos display)
{
//animator.SetBool("IsOpen", true) ;
//eventSystemMainCanvas.enabled = false;
titleText.text = display.title.ToString();
Debug.Log(titleText.text = display.title.ToString());
sentences.Clear();
foreach (LocalizedString strings in display.sentences)
{
var sentence = strings.GetLocalizedString().ToString();
sentences.Enqueue(sentence);
}
DisplayNextSentence();
}
public void EndInfos(Infos display)
{
EndDisply();
}
public void DisplayNextSentence()
{
if (sentences.Count == 0) {
EndDisply();
return;
}
string sentence = sentences.Dequeue();
infoText.text = sentence;
}
// public void Close()
//{
//close = true;
// animator.SetBool("IsOpen", false);
//eventSystemMainCanvas.enabled = true;
//}
private void EndDisply()
{
Debug.Log("END!!");
}
}