Пример #1
0
        /// <summary>
        ///     Set a tile at the given position using an id.
        /// </summary>
        /// <param name="tilePosition">The position at which to set the tile.</param>
        /// <param name="tileId">The id of the tile to set.</param>
        public void SetTileAt(Vector3Int tilePosition, string tileId)
        {
            if (!IsValidPosition(tilePosition))
            {
                Debug.LogError($"Position {tilePosition} is not valid for Chunk at {position}");
                return;
            }

            // If it's an empty id, trying to remove the tile
            if (string.IsNullOrEmpty(tileId))
            {
                RemoveTileAt(tilePosition);
                return;
            }

            // Get the corresponding BasicTile and call SetTileAt with the BasicTile
            BasicTile tile = TileDB.GetTile(tileId);

            SetTileAt(tilePosition, tile);
        }
Пример #2
0
        /// <summary>
        ///     Loads the current tiles array into the tilemap.
        /// </summary>
        private void LoadTilesToTilemap()
        {
            // Keep a list of tiles/positions to push to the tilemap later
            Dictionary <Vector3Int, TileBase> tilesToAdd = new Dictionary <Vector3Int, TileBase>();

            // Load every tile
            for (int index = 0; index < tiles.Length; index++)
            {
                Vector3Int tilePosition =
                    LocalChunkToTilePosition(IndexToPosition(index));

                string tileId = tiles[index];

                if (!string.IsNullOrEmpty(tileId))
                {
                    tilesToAdd.Add(tilePosition, TileDB.GetTile(tileId));
                }
            }

            // Set all of the tiles that aren't empty in the tilemap
            Tilemap.SetTiles(tilesToAdd.Keys.ToArray(), tilesToAdd.Values.ToArray());
        }
Пример #3
0
        private void Awake()
        {
            if (instance == null)
            {
                instance = this;
            }
            else
            {
                Debug.LogError("Cannot have more than one TileDB instance.");
            }

            if (tiles == null || tiles.Count == 0)
            {
                Debug.LogError("Tile list is null or empty in TileDB.");
            }
            else
            {
                foreach (BasicTile tile in tiles)
                {
                    tileDatabase.Add(tile.Id, tile);
                }
            }
        }