Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Resources;
- using Assets.Scripts.Helpers;
- using UnityEngine;
- using SimpleJson;
- namespace Assets.Scripts
- {
- public sealed class LangSingleton
- {
- private readonly Dictionary<string, string> ourText = new Dictionary<string, string>();
- private static readonly LangSingleton instance = new LangSingleton();
- public static LangSingleton Instance
- {
- get { return instance; }
- }
- protected LangSingleton()
- {
- ChangeLang("eng");
- }
- private void GetText(TextAsset asset)
- {
- if (asset == null)
- {
- return;
- }
- ourText.Clear();
- var jsonText = JSON.Parse((asset.ToString()));
- foreach (var i in jsonText)
- {
- ourText.Add(
- jsonText[i]["key"],
- jsonText[i]["value"]);
- }
- }
- public string GetValue(string key)
- {
- return ourText.ContainsKey(key)?ourText(key):string.empty;
- }
- public void ChangeLang(string lng)
- {
- TextAsset asset;
- if (lng = "ru")
- {
- asset = Resources.Load("ru") as TextAsset;
- }
- else
- {
- asset = Resources.Load("eng") as TextAsset;
- }
- GetText(asset);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment