Exemplo n.º 1
0
    private List <VectorTile> GetNeighbors(VectorTile tile, List <VectorTile> tiles)
    {
        List <VectorTile> neighbors = new List <VectorTile>();

        // Creates the box to check all the neighbors
        RectInt.PositionEnumerator positions = new RectInt(tile.Position.x - 1, tile.Position.y - 1, 3, 3).allPositionsWithin;

        while (positions.MoveNext())
        {
            // Skip to next tile if it is the original tile.
            if (positions.Current == tile.Position)
            {
                continue;
            }

            // Checks the VectorTile list to see if there is a tile with the current position.
            VectorTile neighborTile = tiles.Find(t => t.Position == positions.Current);

            // If tile was found, add it to the neighbors list
            if (neighborTile != default(VectorTile))
            {
                neighbors.Add(neighborTile);
            }
        }

        return(neighbors);
    }
Exemplo n.º 2
0
    private void InitizalizeVectorTilePool()
    {
        // Creates VectorTile Pool for reusability and reduced memory usage.
        _vectorTilesPool = new List <VectorTile>();
        _map.CompressBounds(); // Important step when every working with Unity Tilemaps.

        RectInt.PositionEnumerator positions = new RectInt
                                                   (Vector2Int.FloorToInt(_map.localBounds.min),                     // Bottom Right Corner.
                                                   Vector2Int.FloorToInt(_map.localBounds.size)).allPositionsWithin; // Width x Height.

        while (positions.MoveNext())
        {
            if (_map.HasTile(Vector3Int.FloorToInt((Vector2)positions.Current)))
            {
                _vectorTilesPool.Add(new VectorTile(positions.Current));
            }
        }
    }