private void Copy_Over(List <Tilemap> i_from, List <Tilemap> i_to, int i_index, bool i_do_convert_to_world) { foreach (var tile in ship_tile_positions) { Vector3Int pos = tile.Key; if (i_do_convert_to_world) { Vector3 float_pos = ship_grid.CellToWorld(pos); pos.x = Mathf.RoundToInt(float_pos.x); pos.y = Mathf.RoundToInt(float_pos.y); tm.Add_Tile(pos, i_from[i_index].GetTile(tile.Key), ship_grid.transform.rotation); tm.Ship_Remove_Tile(tile.Key, i_from[i_index].GetTile(tile.Key)); } else { tm.Ship_Add_Tile(pos, i_from[i_index].GetTile(tile.Key), i_from[i_index].GetTransformMatrix(pos).rotation); tm.Remove_Tile(tile.Key, i_from[i_index].GetTile(tile.Key)); } } }
private void Spread_Neighbour(Vector3Int i_pos) { TileBase liquid_tile; Tilemap liquid_tilemap; //spawner_tile = system_tiles["Spawner"][0]; liquid_tile = liquid_dictionary[i_pos].tile; if (is_ship_mode) { //spawner_tile = system_tiles["Spawner"][0]; liquid_tilemap = tm.Grab_Ship_Layer(liquid_tile); } else { liquid_tilemap = tm.Grab_Layer(liquid_tile); } Vector3Int up_neighbour = i_pos + Vector3Int.up; if (Capacity_Compare(i_pos, up_neighbour)) { if (!liquid_dictionary.ContainsKey(up_neighbour)) { Drain(i_pos, up_neighbour); if (is_ship_mode) { tm.Ship_Add_Tile(up_neighbour, liquid_tile); } else { tm.Add_Tile(up_neighbour, liquid_tile); } } else { Equalize(i_pos, up_neighbour); } } Vector3Int down_neighbour = i_pos + Vector3Int.down; if (Capacity_Compare(i_pos, down_neighbour)) { if (!liquid_dictionary.ContainsKey(down_neighbour)) { Drain(i_pos, down_neighbour); if (is_ship_mode) { tm.Ship_Add_Tile(down_neighbour, liquid_tile); } else { tm.Add_Tile(down_neighbour, liquid_tile); } } else { Equalize(i_pos, down_neighbour); } } Vector3Int left_neighbour = i_pos + Vector3Int.left; if (Capacity_Compare(i_pos, left_neighbour)) { if (!liquid_dictionary.ContainsKey(left_neighbour)) { Drain(i_pos, left_neighbour); if (is_ship_mode) { tm.Ship_Add_Tile(left_neighbour, liquid_tile); } else { tm.Add_Tile(left_neighbour, liquid_tile); } } else { Equalize(i_pos, left_neighbour); } } Vector3Int right_neighbour = i_pos + Vector3Int.right; if (Capacity_Compare(i_pos, right_neighbour)) { if (!liquid_dictionary.ContainsKey(right_neighbour)) { Drain(i_pos, right_neighbour); if (is_ship_mode) { tm.Ship_Add_Tile(right_neighbour, liquid_tile); } else { tm.Add_Tile(right_neighbour, liquid_tile); } } else { Equalize(i_pos, right_neighbour); } } }
// Update is called once per frame void Update() { Selection_Update(); inventory_debug_show.text = "Slot: " + slot_selection + ": " + tile_inventory[slot_selection].amount; Vector3Int rounded_cursor_pos = new Vector3Int(); rounded_cursor_pos.x = Mathf.FloorToInt(cursor_obj.Get_World_Position().x); rounded_cursor_pos.y = Mathf.FloorToInt(cursor_obj.Get_World_Position().y); rounded_cursor_pos.z = 0; RaycastHit2D hit = Physics2D.Raycast(transform.position, rounded_cursor_pos - transform.position, Vector3.Distance(transform.position, rounded_cursor_pos)); Vector3 hit_position; if (hit.collider != null) { hit_position = hit.point; } else { hit_position = cursor_obj.Get_World_Position(); } float distance = Vector2.Distance(hit_position, cursor_obj.Get_World_Position()); if (distance < 1.0f) { if ((Input.GetMouseButton(0)) && (tile_inventory[slot_selection].amount > 0)) { if (alternate_floor_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (alternate_place_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) == null) { tm.Ship_Add_Tile(ship_grid.WorldToCell(cursor_obj.Get_World_Position()), place_tile); tile_count--; } } else if (floor_tilemap.GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) == null) { tm.Add_Tile(default_grid.WorldToCell(cursor_obj.Get_World_Position()), tile_inventory[slot_selection].tile); tile_inventory[slot_selection].amount--; } } } if (Input.GetMouseButton(1)) { if (alternate_floor_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { if (alternate_place_tilemap.GetTile(ship_grid.WorldToCell(cursor_obj.Get_World_Position())) == place_tile) { tm.Ship_Remove_Tile(ship_grid.WorldToCell(cursor_obj.Get_World_Position()), place_tile); tile_count++; } } else if (floor_tilemap.GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) != null) { TileBase temp = tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())); if (tm.Grab_Layer(tile_inventory[slot_selection].tile).GetTile(default_grid.WorldToCell(cursor_obj.Get_World_Position())) == tile_inventory[slot_selection].tile) { tm.Remove_Tile(default_grid.WorldToCell(cursor_obj.Get_World_Position()), tile_inventory[slot_selection].tile); tile_inventory[slot_selection].amount++; } } } } }
private void Convert_Neighbour(Vector3Int i_pos) { bool has_spread = false; TileBase spawner_tile; Tilemap spawner_tilemap; //spawner_tile = system_tiles["Spawner"][0]; spawner_tile = swarm_dictionary[i_pos].tile; if (is_ship_mode) { //spawner_tile = system_tiles["Spawner"][0]; spawner_tilemap = tm.Grab_Ship_Layer(spawner_tile); } else { spawner_tilemap = tm.Grab_Layer(spawner_tile); } Vector3Int up_neighbour = i_pos + Vector3Int.up; if ((spawner_tilemap.GetTile(up_neighbour) != null) && (Count_Swarm_Neighbours(up_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(up_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(up_neighbour, spawner_tile); } else { tm.Add_Tile(up_neighbour, spawner_tile); } has_spread = true; } } Vector3Int down_neighbour = i_pos + Vector3Int.down; if (((spawner_tilemap.GetTile(down_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(down_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(down_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(down_neighbour, spawner_tile); } else { tm.Add_Tile(down_neighbour, spawner_tile); } has_spread = true; } } Vector3Int left_neighbour = i_pos + Vector3Int.left; if (((spawner_tilemap.GetTile(left_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(left_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(left_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(left_neighbour, spawner_tile); } else { tm.Add_Tile(left_neighbour, spawner_tile); } has_spread = true; } } Vector3Int right_neighbour = i_pos + Vector3Int.right; if (((spawner_tilemap.GetTile(right_neighbour) != null) && (!has_spread)) && (Count_Swarm_Neighbours(right_neighbour) < 2)) { if (!swarm_dictionary.ContainsKey(right_neighbour)) { if (is_ship_mode) { tm.Ship_Add_Tile(right_neighbour, spawner_tile); } else { tm.Add_Tile(right_neighbour, spawner_tile); } has_spread = true; } } }