101 lines
2.8 KiB
C#
101 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public enum LocaleType
|
|
{
|
|
Korean = 0,
|
|
English = 1,
|
|
ChineseSimplified = 2,
|
|
Spanish = 3
|
|
}
|
|
|
|
public class LocalizationManager : Singleton<LocalizationManager>
|
|
{
|
|
public bool IsInitialized;
|
|
|
|
[SerializeField]
|
|
private Material _defaultFontMaterial;
|
|
|
|
private bool _isChanging;
|
|
|
|
private static readonly int OutlineWidthHash = Shader.PropertyToID("_OutlineWidth");
|
|
|
|
private void Start()
|
|
{
|
|
var index = ES3.Load(SaveData.Locale, GetCurrentLocaleIndex());
|
|
ChangeLocale((LocaleType)index, () => IsInitialized = true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>0 - 한국어</para>
|
|
/// 1 - 영어
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
[Button("언어 변경")]
|
|
public void ChangeLocale(LocaleType localeType, Action completeEvent = null)
|
|
{
|
|
if (_isChanging) return;
|
|
|
|
StartCoroutine(ChangeLocaleCoroutine(localeType, completeEvent));
|
|
}
|
|
|
|
private IEnumerator ChangeLocaleCoroutine(LocaleType localeType, Action completeEvent)
|
|
{
|
|
_isChanging = true;
|
|
|
|
yield return LocalizationSettings.InitializationOperation;
|
|
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[(int)localeType];
|
|
|
|
if (localeType == LocaleType.ChineseSimplified)
|
|
{
|
|
SetMaterialOutline(0.1f);
|
|
}
|
|
else
|
|
{
|
|
SetMaterialOutline(0.2f);
|
|
}
|
|
ES3.Save(SaveData.Locale, (int)localeType);
|
|
|
|
_isChanging = false;
|
|
completeEvent?.Invoke();
|
|
}
|
|
|
|
public int GetCurrentLocaleIndex()
|
|
{
|
|
var selectedLocale = LocalizationSettings.SelectedLocale;
|
|
var locales = LocalizationSettings.AvailableLocales.Locales;
|
|
|
|
for (var i = 0; i < locales.Count; i++)
|
|
{
|
|
if (locales[i] == selectedLocale)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public string GetLocaleDisplayName(LocaleType localeType)
|
|
{
|
|
return localeType switch
|
|
{
|
|
LocaleType.Korean => "한국어",
|
|
LocaleType.English => "English",
|
|
LocaleType.ChineseSimplified => "中文(简体)",
|
|
LocaleType.Spanish => "Español",
|
|
_ => "Unknown"
|
|
};
|
|
}
|
|
|
|
public void SetMaterialOutline(float value)
|
|
{
|
|
_defaultFontMaterial.SetFloat(OutlineWidthHash, value);
|
|
}
|
|
}
|
|
}
|