Any examples?
Hey we dont have any examples of this yet. The plan is to do a deeper integration with TMP in the future. For now it should be similiar to the UI Text example. Just hook up the UnityEvents.
1 Like
This is the same example code as the documentation modified to work with TMPro Dropdown.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization.Settings;
using TMPro;
public class LocaleDropdown : MonoBehaviour
{
public TMP_Dropdown dropdown;
IEnumerator Start()
{
// Wait for the localization system to initialize, loading Locales, preloading etc.
yield return LocalizationSettings.InitializationOperation;
// Generate list of available Locales
var options = new List<TMP_Dropdown.OptionData>();
int selected = 0;
for (int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
{
var locale = LocalizationSettings.AvailableLocales.Locales[i];
if (LocalizationSettings.SelectedLocale == locale)
selected = i;
options.Add(new TMP_Dropdown.OptionData(locale.name));
}
dropdown.options = options;
dropdown.value = selected;
dropdown.onValueChanged.AddListener(LocaleSelected);
}
static void LocaleSelected(int index)
{
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
}
}
1 Like