private void CalculateTotalResources() { Building building = GetComponent <Building>(); Details currentBuildingDetails = GetComponent <Details>(); // Search for resources in building bounds/area foreach (var boundCell in building.buildingMapBounds.allPositionsWithin) { // Get details of each tile in bounds Details resourceDetails = TileHelper.GetResourceDetailsFromMap((Vector3Int)boundCell, building.buildingTileMap); // Check for any resources if (resourceDetails && resourceDetails.unit.buildingId == currentBuildingDetails.unit.id) { // Add specified resource to dictionary if (!totalResources.Exists(resource => resource.id == resourceDetails.unit.id)) { totalResources.Add(new MineResource { id = resourceDetails.unit.id, count = resourceDetails.unit.count }); } else { // Pick resource by id and add resources count MineResource includedResource = totalResources.Find(resource => resource.id == resourceDetails.unit.id); includedResource.count += resourceDetails.unit.count; } } } }
public void OnConfirmProduction() { if (selectedOption == null) { return; } resource = totalResources.Find(res => res.id == selectedOption.id); // Find selected mine option in available resources and set as default if (resource != null) { // confirm production isWorking = true; } }