private void SetupTileChildren() { var treeTiles = new Array <Vector2>(pathfindingTileMap.GetUsedCells()).Where(treeTile => pathfindingTileMap.GetCell((int)treeTile.x, (int)treeTile.y) == pathfindingTileMap.treeId); foreach (var treeTile in treeTiles) { var parentUniqueId = pathfindingTileMap.GetIdForTile(treeTile); var overlappingTiles = GetOverlappingTiles(treeTile); foreach (var overlappingTile in overlappingTiles) { var uniqueTileId = pathfindingTileMap.GetIdForTile(overlappingTile); if (tileMapObjects.TryGetValue(uniqueTileId, out var tileMapObjectNodeReference)) { pathfindingTileMap.SetCell((int)overlappingTile.x, (int)overlappingTile.y, pathfindingTileMap.playerTraversableId); tileMapObjectNodeReference.parents.Add(parentUniqueId); } else { throw new Exception("Expected already setup tileMapObjectNodeReference!"); } } } }
private void AddTileMapObject(Vector2 tile, Node2D tmpContainerNode) { var tileId = pathfindingTileMap.GetCell((int)tile.x, (int)tile.y); var tileUniqueId = pathfindingTileMap.GetIdForTile(tile); var worldPosition = pathfindingTileMap.MapToWorld(tile) + pathfindingTileMap.CellSize / 2; tileIdToPackedSceneMapping.TryGetValue(tileId, out var packedScene); if (packedScene?.Instance() is TileMapObject tileMapObject) { if (tileMapObjects.TryGetValue(tileUniqueId, out var tileMapObjectNodeReference)) { tileMapObjectNodeReference.node = tileMapObject; tmpContainerNode.AddChild(tileMapObjectNodeReference.node); tileMapObjectNodeReference.node.ZIndex = (int)tile.y * 2; tileMapObjectNodeReference.node.SetPosition(worldPosition); } else { throw new Exception("Expected already setup tileMapObjectNodeReference!"); } } // else { // throw new Exception("Instance is not a tileMapObject"); // } }