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!");
                    }
                }
            }
        }
Esempio n. 2
0
        public TraversableTileMapObject FindRandomPosition()
        {
            var traversableTileMapObjects = tileMapManipulator.GetTileMapObjectsOfType <TraversableTileMapObject>()
                                            .Where(traversableTileMapObject => pathfindingTileMap.GetCell((int)traversableTileMapObject.GetTileMapPosition().x, (int)traversableTileMapObject.GetTileMapPosition().y) == pathfindingTileMap.traversableId).ToList();

            if (traversableTileMapObjects.Count == 0)
            {
                return(null);
            }

            var random      = new Random();
            var randomIndex = random.Next(0, traversableTileMapObjects.Count);

            return(traversableTileMapObjects[randomIndex]);
        }