private void Build() { if (!canBuild || manageDialog.IsPointerOverBuildingDialog()) { return; } if (!Economy.CanBuy(selectedBuildingUnit.price)) { return; } GameObject newBuildingObject = Instantiate( buildingPrefab, createdBuildings.transform, true ); buildingsTileMap.SetTile(currentCell, currentBuildingTile); // GameStore.SetBuildingPosition(currentArea); newBuildingObject.GetComponent <Building>() .SetInitialValues(currentArea, resourcesMap, selectedBuildingUnit); foreach (var boundCell in currentArea.allPositionsWithin) { // Add building position/bound to list GameStore.SetBuildingPosition(boundCell); } }
public void RefreshBuildBound() { // mark current position as old previousCell = currentCell; // set new position currentCell = MouseMoveController.GetMousePositionOnTileMap(hoverTileMap); // build rectangles previousArea = CreateRectangleArea(previousCell); currentArea = CreateRectangleArea(currentCell); // clear build flag canBuild = true; bool isInBuildingsPositions = false; foreach (Vector2Int previousAreaCell in previousArea.allPositionsWithin) { foreach (Vector2Int currentAreaCell in currentArea.allPositionsWithin) { isInBuildingsPositions = GameStore.GetAllBuildingsPositions().Contains(currentAreaCell); if (isInBuildingsPositions) { canBuild = false; break; } } hoverTileMap.SetTile((Vector3Int)previousAreaCell, null); if (isInBuildingsPositions || !Economy.CanBuy(selectedBuildingUnit.price)) { TileHelper.SetTiles(hoverTileMap, hoverTileDenied, currentArea); } else { hoverTileMap.SetTile(currentCell, currentBuildingTile); } } }