Created
June 7, 2021 19:03
-
-
Save ninpl/78a3eac597feb1486132124d8445b543 to your computer and use it in GitHub Desktop.
Guardar y cargar el idioma sin mantenerlo en cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cargar Idioma | |
private void LoadLanguage() | |
{ | |
var savedLanguage = GetSavedLanguage(); | |
if (savedLanguage != Idioma.Desconocido) | |
{ | |
Localizacion.Instancia.IdiomaActual = savedLanguage; | |
} | |
} | |
private Idioma GetSavedLanguage() | |
{ | |
if (PlayerPrefs.HasKey(m_PrefKey)) | |
{ | |
var languageCode = PlayerPrefs.GetString(m_PrefKey, ""); | |
var language = DataLocalizacion.Instancia.IdiomasDisponibles.FirstOrDefault(x => x.Codigo == languageCode); | |
if (language != null) return language; | |
} | |
return Idioma.Desconocido; | |
} | |
// Guardar Idioma | |
private void SaveLanguage() | |
{ | |
PlayerPrefs.SetString(m_PrefKey, Localizacion.Instancia.IdiomaActual.Codigo); | |
PlayerPrefs.Save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment