/// <summary> /// Tries to destroy room at specific location /// </summary> /// <param name="location">Location where to destroy</param> /// <returns>Returns true if room was destroyed</returns> public bool TryDestroyRoom(Room.GridLocation location) { if (RoomGrid.TryGetValue(location, out Room room)) { Destroy(room.gameObject); RoomGrid.Remove(location); return(true); } return(false); }
/// <summary> /// Creates room and adds it to <see cref="RoomGrid"/> /// </summary> /// <param name="location">Location in the grid</param> /// <param name="replace">Will replace room at that location if set true</param> /// <typeparam name="T"></typeparam> /// <returns>Returns created room</returns> public Room CreateRoom <T>(Room.GridLocation location, bool replace = true) where T : Room { if (replace) { TryDestroyRoom(location); } if (!replace && RoomGrid.ContainsKey(location)) { return(null); } var prefab = PrefabHelper.GetRoomPrefab <T>(); var newRoom = Instantiate(prefab, transform).GetComponent <Room>(); newRoom.Create(location); newRoom.Populate(); RoomGrid.Add(location, newRoom); return(newRoom); }