Example #1
0
    public void Load()
    {
        Debug.Log("After Load Data :" + jsonGameMode);
        dataGameModes.Clear();


        if (!string.IsNullOrEmpty(jsonGameMode))
        {
            DataMode[] datas = JsonArray.FromJson <DataMode>(jsonGameMode);
            for (int i = 0; i < datas.Length; i++)
            {
                dataGameModes.Add(datas[i]);
            }
        }
        else
        {
            foreach (var enumValue in Enum.GetValues(typeof(DataGameMode)))
            {
                DataMode mode = new DataMode();
                mode.dataGameMode = (DataGameMode)enumValue;
                mode.bestScore    = 0;
                mode.currentScore = 0;
                dataGameModes.Add(mode);
            }
            Save();
        }
    }
Example #2
0
 /// Returns null on error.
 public static PlayerStats[] GetCompetitorStatsResult(UnityWebRequest finishedRequest)
 {
     if (!CheckFinishedRequest(finishedRequest))
     {
         return(null);
     }
     return(JsonArray.FromJson <PlayerStats>(finishedRequest.downloadHandler.text));
 }
        public void FromJson_SerializableArray_ReturnsArray()
        {
            var serializer = new JsonSerializer();
            var json       = new JsonArray {
                new JsonObject {
                    { "StringProp", "this" }, { "IntProp", 0 }
                }, new JsonObject {
                    { "StringProp", "that" }, { "IntProp", 1 }
                }
            };
            var expected = new List <JsonSerializableClass> {
                new JsonSerializableClass("this", 0), new JsonSerializableClass("that", 1)
            };
            var actual = json.FromJson <JsonSerializableClass>(serializer);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }