Skip to content

Instantly share code, notes, and snippets.

@gegagome
Created February 1, 2020 18:02
Show Gist options
  • Save gegagome/2088a13a30112e83fbff2ed026dbea1c to your computer and use it in GitHub Desktop.
Save gegagome/2088a13a30112e83fbff2ed026dbea1c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "KIDpedia Data")]
public class KIDpediaData : ScriptableObject
{
[Header("Language selector")]
public KIDpediaLanguage _selectedLanguage;
SystemLanguage _selectedSystemLanguage = SystemLanguage.English;
public enum KIDpediaLanguage {
English,
Unknown,
Spanish,
French,
German
}
int _numberOfLanguages = 5;
const string LANGUAGE_SELECTED = "Language Selected";
void OnEnable()
{
SetLanguage(GetLanguageFromPlayerPrefs());
}
public void SetLanguage (string language)
{
switch(language)
{
case "English_US":
Debug.Log("MADE IT HERE");
_selectedLanguage = KIDpediaLanguage.English;
_selectedSystemLanguage = SystemLanguage.English;
break;
case "Unknown":
_selectedLanguage = KIDpediaLanguage.Unknown;
_selectedSystemLanguage = SystemLanguage.Unknown;
break;
case "Spanish":
ReturnIfNotPremium ();
if(IAPManager._iapManager.IsPremium())
{
_selectedLanguage = KIDpediaLanguage.Spanish;
_selectedSystemLanguage = SystemLanguage.Spanish;
}
break;
case "French":
ReturnIfNotPremium ();
if(IAPManager._iapManager.IsPremium())
{
_selectedLanguage = KIDpediaLanguage.French;
_selectedSystemLanguage = SystemLanguage.French;
}
break;
case "German":
ReturnIfNotPremium ();
if(IAPManager._iapManager.IsPremium())
{
_selectedLanguage = KIDpediaLanguage.German;
_selectedSystemLanguage = SystemLanguage.German;
}
break;
}
StoreSelectedLanguage(_selectedSystemLanguage.ToString());
}
public SystemLanguage GetSystemLanguage ()
{
return _selectedSystemLanguage;
}
void StoreSelectedLanguage(string selectedLanguage)
{
PlayerPrefs.SetString(LANGUAGE_SELECTED, selectedLanguage);
}
public string GetLanguageFromPlayerPrefs()
{
string temp = "";
if(PlayerPrefs.HasKey(LANGUAGE_SELECTED))
{
temp = PlayerPrefs.GetString(LANGUAGE_SELECTED);
Debug.Log("HAS KEY " + PlayerPrefs.GetString(LANGUAGE_SELECTED));
}
else
{
temp = "English_US";
PlayerPrefs.SetString(LANGUAGE_SELECTED, temp);
Debug.Log("KEY WAS ADDED");
}
return temp;
}
void OnApplicationQuit()
{}
void ReturnIfNotPremium ()
{
if (IAPManager._iapManager.IsPremium())
{
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment