Beispiel #1
0
 /// <summary>
 /// Start to load all needed data.
 /// </summary>
 /// <exception cref="Exception">OnBiirdInitialized isn't subscribed</exception>
 public void LoadData()
 {
     //todo add version checking
     if (!PlayerPrefs.HasKey("BiirdLocalizationData"))
     {
         _contentCounter = 0;
         _biirdDatabase  = new BiirdDatabase();
         _items          = new Dictionary <string, string>();
         _ids            = BiirdIds.Instance;
         _ids.Init();
         _biirdDatabase.BiirdItems = new List <BiirdItem>();
         StartCoroutine(DownloadData());
     }
     else
     {
         _items = new Dictionary <string, string>();
         string json = PlayerPrefs.GetString("BiirdLocalizationData");
         _biirdDatabase = JsonUtility.FromJson <BiirdDatabase>(json);
         SetDictionary();
         if (OnBiirdInitialized != null)
         {
             OnBiirdInitialized.Invoke();
         }
         else
         {
             throw new Exception(
                       "OnBiirdInitialized should have any subscription before call.\nUse BiirdClient.GetBiird().OnBiirdInitialized+=YOUR_FUNCTION();");
         }
     }
 }
Beispiel #2
0
        private IEnumerator DownloadData()
        {
            yield return(null);

            foreach (var keypair in _ids.AllIds)
            {
                ReceiveTheText(keypair, RegisterDownloadedData);
            }

            yield return(new WaitUntil(() => _contentCounter == _ids.AllIds.Count));

            SetDictionary();

            string jsonData = JsonUtility.ToJson(_biirdDatabase);

            Debug.Log(jsonData);
            PlayerPrefs.SetString("BiirdLocalizationData", jsonData);
            PlayerPrefs.Save();
            if (OnBiirdInitialized != null)
            {
                OnBiirdInitialized.Invoke();
            }
            else
            {
                throw new Exception(
                          "OnBiirdInitialized should have any subscription before call.\nUse BiirdClient.GetBiird().OnBiirdInitialized+=YOUR_FUNCTION();");
            }
        }