31 lines
864 B
C#
31 lines
864 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.Localization;
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
public class LocalizedDropdown : MonoBehaviour
|
|
{
|
|
public TMP_Dropdown dropdown;
|
|
public LocalizedString[] localizedOptions; // Array to store localized strings
|
|
|
|
private void Start()
|
|
{
|
|
UpdateDropdownOptions();
|
|
LocalizationSettings.SelectedLocaleChanged += _ => UpdateDropdownOptions();
|
|
}
|
|
|
|
void UpdateDropdownOptions()
|
|
{
|
|
dropdown.ClearOptions(); // Clear existing options
|
|
List<string> options = new List<string>();
|
|
|
|
foreach (LocalizedString localizedString in localizedOptions)
|
|
{
|
|
options.Add(localizedString.GetLocalizedString()); // Get the localized text
|
|
}
|
|
|
|
dropdown.AddOptions(options); // Add translated options
|
|
}
|
|
}
|