Localization
How To Set Up Localization In Inventool
Issues With uGUI
using UnityEngine;
using TMPro;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
public class LocaleFontAutoSwitcher : MonoBehaviour
{
[System.Serializable]
public class LocaleFontPair
{
public LocaleIdentifier locale;
public TMP_FontAsset font;
}
public LocaleFontPair[] localeFonts;
void OnEnable()
{
LocalizationSettings.SelectedLocaleChanged += OnLocaleChanged;
ApplyFont(LocalizationSettings.SelectedLocale);
}
void OnDisable()
{
LocalizationSettings.SelectedLocaleChanged -= OnLocaleChanged;
}
void OnLocaleChanged(Locale newLocale)
{
ApplyFont(newLocale);
}
void ApplyFont(Locale locale)
{
TMP_FontAsset selectedFont = null;
foreach (var pair in localeFonts)
{
if (pair.locale == locale.Identifier)
{
selectedFont = pair.font;
break;
}
}
if (selectedFont == null)
{
Debug.LogWarning($"No font assigned for locale: {locale.Identifier}");
return;
}
var allTextObjects = GameObject.FindObjectsOfType<TextMeshProUGUI>(true);
foreach (var tmp in allTextObjects)
{
tmp.font = selectedFont;
}
}
}
Last updated