public void TestFromNestedJson() { var json = "{\"nested\":{\"test\":100.01}}"; var t = Piekson.FromJson <TestMainClass>(json); Assert.AreEqual(new TestMainClass(new TestNestedClass()), t); }
public void TestFromEnum() { var json = "{\"TestDirection\":\"DOWN\"}"; var t = Piekson.FromJson <TestClassWithEnum>(json); Assert.AreEqual(new TestClassWithEnum(TestDirection.DOWN).TestDirection, t.TestDirection); }
public void TestToJson() { TestClass t = new TestClass(3.14f, true, 123, "hel\\\"lo"); var json = Piekson.ToJson(t); Assert.AreEqual("{\"a\":123,\"b\":\"hel\\\\\\\"lo\",\"d\":3.14,\"state\":true}", json); }
public void TestNullValue() { var t = new TestMainClass(); var json = Piekson.ToJson(t); Assert.AreEqual("{}", json); }
public void TestNegativeValueFromJson() { var json = "{\"a\":-123,\"b\":\"hel\\\\\\\"lo\",\"d\":-3.14,\"state\":true}"; var t = Piekson.FromJson <TestClass>(json); Assert.AreEqual(new TestClass(-3.14f, true, -123, "hel\\\"lo"), t); }
public void TestEnum() { var t = new TestClassWithEnum(TestDirection.DOWN); var json = Piekson.ToJson(t); Assert.AreEqual("{\"TestDirection\":\"DOWN\"}", json); }
public void TestNestedToJson() { TestMainClass t = new TestMainClass(new TestNestedClass()); var json = Piekson.ToJson(t); Assert.AreEqual("{\"nested\":{\"test\":100.01}}", json); }
public void TestType() { var t = new TestClassWithType(typeof(TestClassWithType)); var json = Piekson.ToJson(t); Assert.AreEqual("{\"type\":\"TestNamespace.TestClassWithType, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\"}", json); }
public void TestLoopToJson() { var t = new TestLoop(10); var json = Piekson.ToJson(t); Assert.AreEqual("{\"a\":10}", json); }
public void TestFromType() { var json = "{\"type\":\"TestNamespace.TestClassWithType, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\"}"; var t = Piekson.FromJson <TestClassWithType>(json); Assert.AreEqual(typeof(TestClassWithType), t.type); }
public void TestNestedGenericCollectionToJson() { var t = new TestNestedCollection(new List <string> { "Arnold", "Marian", "Fedrynand" }); var json = Piekson.ToJson(t); Assert.AreEqual("{\"names\":[\"Arnold\",\"Marian\",\"Fedrynand\"]}", json); }
public void TestGenericCollectionToJson() { List <int> list = new List <int> { 1, 2, 3, 4, 5 }; var json = Piekson.ToJson(list); Assert.AreEqual("[1,2,3,4,5]", json); }
public void TestFromStringListJson() { var json = "[\"a\",\"b\",\"c\",\"d\"]"; var t = Piekson.FromJson <List <string> >(json); Assert.AreEqual(new List <string> { "a", "b", "c", "d" }, t); }
public void TestFromListInObjectJson() { var json = "{\"names\":[\"Arnold\",\"Marian\",\"Fedrynand\"]}"; var t = Piekson.FromJson <TestNestedCollection>(json); Assert.AreEqual(new TestNestedCollection(new List <string> { "Arnold", "Marian", "Fedrynand" }), t); }
public void TestFromObjectInListJson() { var json = "[{\"test\":1},{\"test\":2}]"; var t = Piekson.FromJson <List <TestSimpleClass> >(json); Assert.AreEqual(new List <TestSimpleClass> { new TestSimpleClass(1), new TestSimpleClass(2) }, t); }
public void TestFromIntListJson() { var json = "[1,2,3,4,5,6]"; var t = Piekson.FromJson <List <int> >(json); Assert.AreEqual(new List <int> { 1, 2, 3, 4, 5, 6 }, t); }
public void TestFromDictionaryJson() { var json = "{\"a\":1,\"b\":2,\"c\":3,\"d\":4}"; var t = Piekson.FromJson <Dictionary <string, int> >(json); CollectionAssert.AreEquivalent(new Dictionary <string, int>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", 4 }, }, t); }
public void TestFromDictionaryInObjectJson() { var json = "{\"test\":{\"a\":1, \"b\":3}}"; var t = Piekson.FromJson <TestDictionaryInObject>(json); CollectionAssert.AreEquivalent(new Dictionary <string, int>() { { "a", 1 }, { "b", 3 } }, t.test); }
public void TestFromObjectInDictionaryJson() { var json = "{\"testObj1\":{\"test\":1}, \"testObj2\":{\"test\":2}}"; var t = Piekson.FromJson <Dictionary <string, TestSimpleClass> >(json); CollectionAssert.AreEquivalent( new Dictionary <string, TestSimpleClass>() { { "testObj1", new TestSimpleClass(1) }, { "testObj2", new TestSimpleClass(2) } }, t); }
public void TestDictionaryToJson() { var t = new Dictionary <string, int>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", 4 }, }; var json = Piekson.ToJson(t); Assert.AreEqual("{\"a\":1,\"b\":2,\"c\":3,\"d\":4}", json); }
void Awake() { var levelData = Piekson.FromJson <LevelDto>(Level.Json); spawnSprites(levelData); spawnSpriteShapes(levelData); var carWasSpawned = spawnPrefabs(levelData); if (carWasSpawned) { SEventSystem.FireEvent(EventNames.LEVEL_INSTANTIATED); } else { Debug.Log("Car was not instantiated!"); } }
public void Serialize() { var carSerialized = false; var levelDto = new LevelDto(); for (int i = 0; i < transform.childCount; i++) { var spriteRenderer = transform.GetChild(i).GetComponent <SpriteRenderer>(); var spriteShapeController = transform.GetChild(i).GetComponent <SpriteShapeController>(); var prefab = transform.GetChild(i).GetComponent <ImPrefabSerializeMe>(); if (spriteRenderer != null) { levelDto.sprites.Add(new SpriteDto(spriteRenderer)); } if (spriteShapeController != null) { levelDto.SpriteShapeControllers.Add(new SpriteShapeControllerDto(spriteShapeController)); } if (prefab != null) { if (prefab.GetComponent <Car>() != null) { carSerialized = true; } levelDto.Prefabs.Add(new Prefab(prefab)); } } if (carSerialized) { var level = ScriptableObject.CreateInstance <Level>(); level.Json = Piekson.ToJson(levelDto); AssetDatabase.CreateAsset(level, "Assets/Levels/" + WorldType + "/" + SceneManager.GetActiveScene().name + ".asset"); Debug.Log(Piekson.ToJson(levelDto)); } else { Debug.Log("Car is missing!"); } }