private void GenerateBuildings() { for (int x = 0; x < city.size.x; ++x) { for (int z = 0; z < city.size.z; ++z) { // smooth the information Block block = city.blocks[x, z]; int radius = 5; block.richness = 0; for (int dx = 0; dx < radius; ++dx) { for (int dz = 0; dz < radius; ++dz) { Vector3 cell = new Vector3(x, 0, z) + new Vector3(dx - radius / 2, 0, dz - radius / 2); if (city.ValidCell(cell) && city.blocks[(int)(cell.x), (int)(cell.z)].region != null) { block.richness += city.blocks[(int)(cell.x), (int)(cell.z)].region.richness; } } } block.richness /= radius * radius; // BUILDING FACTORY if (enableBlockMerge && Random.value < blockMergeRatio && AvailableForMergeBlock(x, z)) { Building building = buildingactory.GetMegaBuilding(Random.Range(0.9f, 1.5f) * block.richness * 1.1f); building.transform.parent = block.transform; building.LocalPosition = new Vector3(0.5f, 0, 0.5f); building.transform.localScale = Vector3.one; building.transform.localEulerAngles = new Vector3(0, -90 * Random.Range(-1, 2), 0); building.gameObject.SetActive(true); building.GeneratePaths(); block.superBlock = block; city.blocks[x + 1, z].superBlock = block; city.blocks[x, z + 1].superBlock = block; city.blocks[x + 1, z + 1].superBlock = block; block.building = building; city.blocks[x + 1, z].building = building; city.blocks[x, z + 1].building = building; city.blocks[x + 1, z + 1].building = building; block.building.gameObject.isStatic = true; } else if (block.building == null && !block.isAvenue) { SimpleBuildingGenerate(block); } block.size = new Vector3(1, block.building ? block.building.localSize.y : 0, 1); } } }