private void DeserializeField(string key, Type type) { TextAsset fieldAsset = TestJsonLoader.LoadJson($"/LDtkMockField_Project.json"); //try deserializing field LdtkJson field = JsonConvert.DeserializeObject <LdtkJson>(fieldAsset.text); FieldInstance[] fieldInstances = field.Levels[0].LayerInstances[0].EntityInstances[0].FieldInstances; FieldInstance instance = fieldInstances.First(p => p.Type.Contains(key)); if (instance.Type.Contains("Array")) { object[] objs = ((IEnumerable)instance.Value).Cast <object>() .Select(x => x == null ? x : x.ToString()) .ToArray(); foreach (object o in objs) { object obj = GetObject(type, instance, o); Debug.Log(obj); } } else { object obj = GetObject(type, instance, instance.Value); Debug.Log(obj); } }
public void JsonDeserializeEntityInstance() { TextAsset jsonProject = TestJsonLoader.LoadJson(TestJsonLoader.MOCK_ENTITY_INSTANCE); //try deserializing entity EntityInstance entity = JsonConvert.DeserializeObject <EntityInstance>(jsonProject.text); }
public void JsonDeserializeSchemaProject() { TextAsset jsonProject = TestJsonLoader.LoadJson(BASIC_PROJECT); Assert.NotNull(jsonProject, "Unsuccessful acquirement of json text asset"); //attempt deserializing entire project LdtkJson project = LdtkJson.FromJson(jsonProject.text); }
public void GetLevelBounds() { const string lvlName = "Level"; TextAsset jsonProject = TestJsonLoader.LoadGenericProject(); LdtkJson project = LdtkJson.FromJson(jsonProject.text); Level level = project.Levels.FirstOrDefault(p => p.Identifier == lvlName); LayerInstance layer = level.LayerInstances.FirstOrDefault(p => p.IsIntGridLayer); Rect levelBounds = level.UnityWorldSpaceBounds((int)layer.GridSize); Debug.Log(levelBounds); }
public void GetCorrectTileBits() { TextAsset mockTest = TestJsonLoader.LoadJson(MOCK_TILE); TileInstance[] tiles = JsonConvert.DeserializeObject <TileInstance[]>(mockTest.text); foreach (TileInstance tile in tiles) { Debug.Log($"Tile: {tile.FlipX}, {tile.FlipY}"); } Assert.IsTrue(tiles[0].FlipX == false && tiles[0].FlipY == false); Assert.IsTrue(tiles[1].FlipX == true && tiles[1].FlipY == false); Assert.IsTrue(tiles[2].FlipX == false && tiles[2].FlipY == true); Assert.IsTrue(tiles[3].FlipX == true && tiles[3].FlipY == true); }