Advertisement
elsemTim

Singltone

Sep 13th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Resources;
  3. using Assets.Scripts.Helpers;
  4. using UnityEngine;
  5. using SimpleJson;
  6.  
  7. namespace Assets.Scripts
  8. {
  9.     public sealed class LangSingleton
  10.     {
  11.         private readonly Dictionary<string, string> ourText = new Dictionary<string, string>();
  12.         //создается объект нашего класса
  13.         private static readonly LangSingleton instance = new LangSingleton();
  14.  
  15.         public static LangSingleton Instance
  16.         {
  17.             //тут типо возвращаем значение нашего объекта..
  18.             get { return instance; }
  19.         }
  20.  
  21.         //
  22.  
  23.  
  24.         // защищённый конструктор нужен, чтобы предотвратить создание экземпляра класса Singleton
  25.         protected LangSingleton() { }
  26.  
  27.         private void getText()
  28.         {
  29.  
  30.             TextAsset asset = Resources.Load("ru") as TextAsset;
  31.             if (asset != null)
  32.             {
  33.                 ourText.Clear();
  34.                 var jsonText = JSON.Parse((asset.ToString()));
  35.                 for (int i = 0; i < jsonText.Count; i++)
  36.                 {
  37.                      ourText.Add(
  38.                         jsonText[i]["key"],
  39.                         jsonText[i]["value"]);
  40.                 }
  41.             }
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement