Пример #1
0
    public static bool SetDefaultDataForFirstTime(string jsonFile)
    {
        isInStart = false;
        Timer.Reset();
        data = FlatHelper.FromJson <PlayerDataModel>(jsonFile);

        if (!HasKey("isRefreshDataEveryLaunch") || GetData <int>("isRefreshDataEveryLaunch") == 1)
        {
            Clear();
            foreach (var property in typeof(PlayerDataModel).GetFields())
            {
                if (property.GetValue(data).GetType() == typeof(List <VideoAdsDataModel>))
                {
                    jsonData = FlatHelper.ToJson <VideoAdsDataModel>(property.GetValue(data));
                    SaveData(property.Name, jsonData);
                }
                else if (property.GetValue(data).GetType() == typeof(List <ThemesDataModel>))
                {
                    jsonData = FlatHelper.ToJson <ThemesDataModel>(property.GetValue(data));
                    SaveData(property.Name, jsonData);
                }
                else if (property.GetValue(data).GetType() == typeof(List <MyTuples>))
                {
                    jsonData = FlatHelper.ToJson <MyTuples>(property.GetValue(data));
                    SaveData(property.Name, jsonData);
                }
                else
                {
                    SaveData(property.Name, property.GetValue(data));
                }
            }

            isInStart = true;
            return(true);
        }
        else
        {
            RefreshModel();
            isInStart = true;
            return(false);
        }
    }
Пример #2
0
    static void RefreshModel()
    {
        foreach (var property in typeof(PlayerDataModel).GetFields())
        {
            if (property.GetValue(data).GetType() == typeof(List <VideoAdsDataModel>))
            {
                data.videoAds.Clear();
                string[] strArr = GetData <string>(property.Name).Split('|');
                for (int i = 0; i < strArr.Length; i++)
                {
                    jsonAdsData1 = FlatHelper.FromJson <VideoAdsDataModel>(strArr[i]);
                    data.videoAds.Add(jsonAdsData1);
                }
            }
            else if (property.GetValue(data).GetType() == typeof(List <ThemesDataModel>))
            {
                if (property.Name == "theme1")
                {
                    data.theme1.Clear();
                }
                else
                {
                    data.theme2.Clear();
                }

                string[] strArr = GetData <string>(property.Name).Split('|');
                for (int i = 0; i < strArr.Length; i++)
                {
                    jsonAdsData2 = FlatHelper.FromJson <ThemesDataModel>(strArr[i]);
                    if (property.Name == "theme1")
                    {
                        data.theme1.Add(jsonAdsData2);
                    }
                    else
                    {
                        data.theme2.Add(jsonAdsData2);
                    }
                }
            }
            else if (property.GetValue(data).GetType() == typeof(List <MyTuples>))
            {
                if (property.Name == "uncompletedLevel")
                {
                    data.uncompletedLevel.Clear();
                    string[] strArr = GetData <string>(property.Name).Split('|');
                    for (int i = 0; i < strArr.Length; i++)
                    {
                        jsonGridData = FlatHelper.FromJson <MyTuples>(strArr[i]);
                        data.uncompletedLevel.Add(jsonGridData);
                        // Debug.Log(jsonGridData.x + "," + jsonGridData.y + " > " + jsonGridData.isFull);
                    }
                }
                else
                {
                    data.savedShapes.Clear();
                    string[] strArr = GetData <string>(property.Name).Split('|');
                    for (int i = 0; i < strArr.Length; i++)
                    {
                        jsonGridData = FlatHelper.FromJson <MyTuples>(strArr[i]);
                        data.savedShapes.Add(jsonGridData);
                        // Debug.Log(jsonGridData.x + "," + jsonGridData.y + " > " + jsonGridData.isFull);
                    }
                }
            }
            else
            {
                var type = property.GetValue(data).GetType();
                if (type == typeof(float))
                {
                    property.SetValue(data, GetData <float>(property.Name));
                }
                else if (type == typeof(int))
                {
                    property.SetValue(data, GetData <int>(property.Name));
                }
                else if (type == typeof(string))
                {
                    property.SetValue(data, GetData <string>(property.Name));
                }
                else if (type == typeof(bool))
                {
                    property.SetValue(data, GetData <bool>(property.Name));
                }
            }
        }
    }