Пример #1
0
        IEnumerator LoadRemoteConfig(bool applyImmediately)
        {
            WWW www = new WWW(settings.RemoteConfigUrl);

            yield return(www);

            if (www.error == null)
            {
                try
                {
                    var config = JsonUtility.FromJson <AdConfig>(www.text);
                    if (config == null || !config.IsSupported)
                    {
                        yield break;
                    }
                    if (applyImmediately)
                    {
                        remoteConfig = config;
                    }
                    // Chỉ lưu json khi đảm bảo nó convert được sang object
                    PlayerPrefs.SetString(KeyRemoteConfigAd, www.text);
                    PlayerPrefs.Save();
                }
                catch (Exception)
                {
                    //CLog.Warn(this, "Existing config is corrupted");
                }
            }
            // Không gửi request tiếp nếu bị lỗi => giảm traffic đến server
        }
Пример #2
0
        void InitRemoteConfig()
        {
            if (!settings.ActiveRemoteConfig)
            {
                PlayerPrefs.DeleteKey(KeyRemoteConfigAd);
                return;
            }
            //CLog.Log(this, "Init remote config");
            // Kiểm tra config đã lưu
            string json = PlayerPrefs.GetString(KeyRemoteConfigAd, null);

            if (!string.IsNullOrEmpty(json))
            {
                // try to convert
                try
                {
                    var cachedRemoteConfig = JsonUtility.FromJson <AdConfig>(json);
                    // Không sử dụng cached của phien bản khác
                    if (cachedRemoteConfig.IsSupported)
                    {
                        PlayerPrefs.DeleteKey(KeyRemoteConfigAd);
                    }
                    else
                    {
                        remoteConfig = cachedRemoteConfig;
                    }
                }
                catch (Exception)
                {
                    //CLog.Warn(this, "Existing config is corrupted");
                }
            }
            //CLog.Log(this, "Inited remote config");
            StartCoroutine(LoadRemoteConfig(remoteConfig == null));
        }