Esempio n. 1
0
    public static bool SetData(string json)
    {
#if UNITY_EDITOR
        if (Instance.offline)
        {
            SeganX.Console.Logger.Enabled = true;
            return(true);
        }
#endif

        var newdata = JsonUtilityEx.FromJson <Data>(json, false);
        if (newdata == null)
        {
            return(false);
        }

        //  set new data
        Instance.data = newdata;
        SaveData(newdata);
        SeganX.Console.Logger.Enabled = DebugMode;

        // select cohort
        Cohort = PlayerPrefsEx.GetInt("GlobalConfig.Cohort", -1);
        if (Cohort < 0)
        {
            Cohort = Random.Range(0, 100) % 2;
            PlayerPrefsEx.SetInt("GlobalConfig.Cohort", Cohort);
        }
        return(true);
    }
Esempio n. 2
0
        public void Save()
        {
            cachedObj.ToList().ForEach(pair =>
            {
                var json          = JsonUtilityEx.ToJson(pair.Value);
                jsonDic[pair.Key] = json;
            });

            var list = jsonDic.Select(pair => new KeyValue()
            {
                key = pair.Key, value = pair.Value
            }).ToList();
            var str = JsonUtilityEx.ToJson(new ListWrapper()
            {
                list = list
            }, true);

            var p   = path;
            var dir = Path.GetDirectoryName(p);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllText(p, str);
        }
Esempio n. 3
0
    public void OnExport(object sender)
    {
        var filename = UnityEditor.EditorUtility.SaveFilePanel("Save exported data", System.IO.Path.GetDirectoryName(Application.dataPath), "config", "txt");

        if (filename.HasContent(4))
        {
            System.IO.File.WriteAllText(filename, JsonUtilityEx.ToJson(data), System.Text.Encoding.UTF8);
        }
    }
Esempio n. 4
0
        void TestConsistency <T>(T v, IEqualityComparer <T> comparer = null)
        {
            var json = JsonUtilityEx.ToJson(v);
            var newV = JsonUtilityEx.FromJson <T>(json);

            if (comparer != null)
            {
                Assert.AreEqual(v, newV, $"{typeof(T).Name} NOT Consistency", comparer);
            }
            else
            {
                Assert.AreEqual(v, newV, $"{typeof(T).Name} NOT Consistency");
            }
        }
Esempio n. 5
0
        public T Get <T>(string key, T defaultValue)
        {
            object obj;

            if (!cachedObj.TryGetValue(key, out obj))
            {
                if (jsonDic.TryGetValue(key, out var json))
                {
                    obj            = JsonUtilityEx.FromJson <T>(json);
                    cachedObj[key] = obj;
                }
            }

            if (obj != null)
            {
                return((T)obj);
            }

            Set(key, defaultValue);
            return(defaultValue);
        }