public void CreateTile(TileCoord pos, Tile tile) { // Make sure the prefab we want to spawn exists, if it doesn't cry in // the console and exit out of this method. if (!(tile.prefab >= 0 && tile.prefab < levelSet.items.Length)) { Debug.LogWarning(string.Format("This tile index {0} is not a valid index: Didn't do anything.", tile.prefab)); return; } // Check to see if a tile is already here if so, windge about it and // return out of this method. if (level.data.ContainsKey(pos)) { return; } if (!spawnedTiles.ContainsKey(pos)) { // Spawn in the prefab. Transform inst = (Transform)Instantiate(levelSet.items[tile.prefab].prefab.transform, new Vector3(0.5f + pos.x, 0, 0.5f + pos.y), Quaternion.identity); inst.SetParent(transform); spawnedTiles.Add(pos, inst); } level.data.Add(pos, tile); }
public void RemoveTile(TileCoord pos) { // See if we have spawned a tile at this pos, if so remove it to stop // null reference exceptions. if (spawnedTiles.ContainsKey(pos)) { Destroy(spawnedTiles[pos].gameObject); } // Next remove the dictionary entries spawnedTiles.Remove(pos); level.data.Remove(pos); }
public void SetTile(TileCoord pos, Tile tile) { if (tile != null) { // Do we already have a tile at this pos? If so then remove it unless // we already have what we want. if (level.data.ContainsKey(pos)) { if (level.data[pos] != tile) { RemoveTile(pos); } } //Create a tile, Duh! CreateTile(pos, tile); } else { RemoveTile(pos); } }
public Tile GetTile(TileCoord pos) { // This just get's a tile and returns it. Very simple. return(level.data[pos]); }