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 languages; void Awake() { FactorySceneMain.Instance.Initialized += OnSceneInitialized; } private void OnSceneInitialized() { languages = LocalizationManager.Instance.AvailableDisplayLanguages; var optoins = new List(); foreach (var language in languages) { optoins.Add(new TMP_Dropdown.OptionData(language.Value)); } dropDown = GetComponent(); 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); } } }