Files
XRLib/Assets/Scripts/Factory/Buttons/UILanguageButton.cs
2025-12-11 21:05:44 +09:00

59 lines
1.6 KiB
C#

using Factory;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UVC.Locale;
namespace UVC.Factory.Buttons
{
public class UILanguageButton : MonoBehaviour
{
private TMP_Dropdown dropDown;
private Dictionary<string, string> languages;
void Awake()
{
FactorySceneMain.Instance.Initialized += OnSceneInitialized;
}
private void OnSceneInitialized()
{
languages = LocalizationManager.Instance.AvailableDisplayLanguages;
var optoins = new List<TMP_Dropdown.OptionData>();
foreach (var language in languages)
{
optoins.Add(new TMP_Dropdown.OptionData(language.Value));
}
dropDown = GetComponent<TMP_Dropdown>();
dropDown.options = optoins;
dropDown.value = languages.Keys.ToList().IndexOf(LocalizationManager.Instance.CurrentLanguage);
dropDown.onValueChanged.AddListener(onValueChanged);
}
void OnDestroy()
{
FactorySceneMain.Instance.Initialized -= OnSceneInitialized;
if (dropDown != null)
{
dropDown.onValueChanged.RemoveListener(onValueChanged);
dropDown = null;
}
}
private void onValueChanged(int value)
{
string selectedLanguage = languages.Keys.ToList()[value];
Debug.Log($"Selected Language: {selectedLanguage}");
LocalizationManager.Instance.SetCurrentLanguage(selectedLanguage);
}
}
}