public void ConstructBuildingOnTile(Vector3Int position, BuildingData buildingOption) { if (!HasRuin(position)) { Debug.LogError($"Position {position} does not have a ruined building to restore"); return; } ConstructionSpace space = _positionToConstructionSpace[position]; Tilemap buildingShape = buildingOption.BuildingShape; GameObject buildingLogic = null; if (buildingOption.LogicPrefab != null) { int buildingCost = GetConstructionCost(buildingOption); if (playerStats.GetMind() - buildingCost < 0) { return; } playerStats.UpdateMind(buildingCost * -1.0f); buildingLogic = Instantiate(buildingOption.LogicPrefab); buildingLogic.transform.position = GetConstructionSpaceWorldCenter(space); _activeBuildingLogic.Add(buildingLogic); OnHealthBonusMayHaveChanged(); buildingLogic.GetComponent <BuildingHealth>().BuildingManager = this; buildingLogic.GetComponent <BuildingLogicBase>().BuildingManager = this; audioManager.PlayBuildingBuilt(); BuildingOnDestroyProxy proxy = buildingLogic.AddComponent <BuildingOnDestroyProxy>(); proxy.OnDestroyEvent.AddListener(() => ReturnToRuin(space, buildingLogic)); } BoundsInt ruinBounds = _positionToConstructionSpace[position].Data.RuinShape.cellBounds; foreach (Vector3Int buildingPosition in buildingShape.cellBounds.allPositionsWithin) { Vector3Int buildingOffsetCompensation = ruinBounds.min - buildingShape.cellBounds.min; Vector3Int mapPosition = space.LocalOrigin + buildingOffsetCompensation + buildingPosition; Map.SetTile(mapPosition, buildingShape.GetTile(buildingPosition)); _positionToBuildingLogic.Add(mapPosition, buildingLogic); } GameObject ruinLogic = _constructionSpaceToRuinLogic[space]; if (ruinLogic != null) { ruinLogic.SetActive(false); } }