// sync relevant data to position offset, e.g. bounding, tilemap tile anchor public void ConfigureRoomWithOffset(Vector3Int offset) { bounding_ = new RoomAABB(bounding_.nw_bound_ + offset.y, bounding_.ne_bound_ + offset.x, bounding_.sw_bound_ + offset.x, bounding_.se_bound_ + offset.y, offset.z); tilemap_.tileAnchor = new Vector3(offset.x, offset.y, offset.z); for (int nw = 0; nw < nw_doors_.Count; nw++) { nw_doors_[nw] = new Door(nw_doors_[nw].orientation_, nw_doors_[nw].grid_position_ + offset); } for (int ne = 0; ne < ne_doors_.Count; ne++) { ne_doors_[ne] = new Door(ne_doors_[ne].orientation_, ne_doors_[ne].grid_position_ + offset); } for (int sw = 0; sw < sw_doors_.Count; sw++) { sw_doors_[sw] = new Door(sw_doors_[sw].orientation_, sw_doors_[sw].grid_position_ + offset); } for (int se = 0; se < se_doors_.Count; se++) { se_doors_[se] = new Door(se_doors_[se].orientation_, se_doors_[se].grid_position_ + offset); } world_height_ = offset.z / 2; game_object_.transform.GetChild(0).gameObject.GetComponent <TilemapRenderer>().sortingOrder = world_height_; }
public bool IsOverlap(RoomAABB room) { if (room.ne_bound_ < sw_bound_ || room.nw_bound_ < se_bound_ || room.se_bound_ > nw_bound_ || room.sw_bound_ > ne_bound_ || room.top_bound_ < bottom_bound_ || room.bottom_bound_ > top_bound_) { return(false); } return(true); }
// ================================================== // // INITIALIZATION FUNCTIONS // ================================================== // public void InitRoom(GameObject gameobject) { // setting tilemap variables game_object_ = gameobject; tilemap_ = game_object_.transform.GetChild(0).gameObject.GetComponent <Tilemap>(); entity_tilemap = game_object_.transform.GetChild(1).gameObject.GetComponent <Tilemap>(); // get used area of tilemap and define its dimensions tilemap_.CompressBounds(); BoundsInt temp_bounds = tilemap_.cellBounds; x_ = temp_bounds.size.x; y_ = temp_bounds.size.y; room_origin_ = temp_bounds.min; tile_list_ = GetTiles(temp_bounds); bounding_ = new RoomAABB(temp_bounds.yMax - 1, temp_bounds.xMax - 1, temp_bounds.xMin, temp_bounds.yMin, layer_height_); world_height_ = 0; }
// Returns a list of Room-Door pairs that fit a target door, and get the offset required to transform // the position of the prefab clone to designated position // Pre : offsetlist empty // Post : offsetlist contains all offsets of room-door pairs public List <Vector2Int> FindRoomsThatFitDoor(Room.Door door, List <int> rooms, string orientation, ref List <Vector3Int> offsetlist) { if (offsetlist.Count > 0) { offsetlist.Clear(); } List <Vector2Int> room_to_door_pair = new List <Vector2Int>(); Vector3Int offset_holder = new Vector3Int(0, 0, 0); if (orientation == "NW") { foreach (int i in rooms) { for (int d = 0; d < room_list_[i].nw_doors_.Count; d++) { // Get the offset of the room to position room.nw_doors_[d] to door offset_holder = room_list_[i].GetPositionOffset(room_list_[i].nw_doors_[d], door); // Get the temporary bounding box used in calculation with the offset RoomAABB temp_aabb = room_list_[i].GetOffsetBounding(offset_holder); bool temp_flag = false; // Test if repositioned bounding box intersects with any existing room, // if not, add it to list to be considered a valid room-door combination foreach (Room r in room_clone_list_) { if (r.bounding_.IsOverlap(temp_aabb)) { temp_flag = true; } } if (!temp_flag) { room_to_door_pair.Add(new Vector2Int(i, d)); offsetlist.Add(offset_holder); } } } } else if (orientation == "NE") { foreach (int i in rooms) { for (int d = 0; d < room_list_[i].ne_doors_.Count; d++) { offset_holder = room_list_[i].GetPositionOffset(room_list_[i].ne_doors_[d], door); RoomAABB temp_aabb = room_list_[i].GetOffsetBounding(offset_holder); bool temp_flag = false; foreach (Room r in room_clone_list_) { if (r.bounding_.IsOverlap(temp_aabb)) { temp_flag = true; } } if (!temp_flag) { room_to_door_pair.Add(new Vector2Int(i, d)); offsetlist.Add(offset_holder); } } } } else if (orientation == "SW") { foreach (int i in rooms) { for (int d = 0; d < room_list_[i].sw_doors_.Count; d++) { offset_holder = room_list_[i].GetPositionOffset(room_list_[i].sw_doors_[d], door); RoomAABB temp_aabb = room_list_[i].GetOffsetBounding(offset_holder); bool temp_flag = false; foreach (Room r in room_clone_list_) { if (r.bounding_.IsOverlap(temp_aabb)) { temp_flag = true; } } if (!temp_flag) { room_to_door_pair.Add(new Vector2Int(i, d)); offsetlist.Add(offset_holder); } } } } else if (orientation == "SE") { foreach (int i in rooms) { for (int d = 0; d < room_list_[i].se_doors_.Count; d++) { offset_holder = room_list_[i].GetPositionOffset(room_list_[i].se_doors_[d], door); RoomAABB temp_aabb = room_list_[i].GetOffsetBounding(offset_holder); bool temp_flag = false; foreach (Room r in room_clone_list_) { if (r.bounding_.IsOverlap(temp_aabb)) { temp_flag = true; } } if (!temp_flag) { room_to_door_pair.Add(new Vector2Int(i, d)); offsetlist.Add(offset_holder); } } } } return(room_to_door_pair); }