public static Mesh Stairwell(float stepWidth, float length, float floorHeight, float slabDepth, float separation, float slabThickness = 0.3f) { List <Mesh> meshes = new List <Mesh>(); float hH = floorHeight / 2; float y = 0; float stairLength = length - 2 * slabDepth; // STAIRS Mesh leftFlight = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f); Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f); leftFlight.Translate(new Vector3(0, y, slabDepth)); rightFlight.Rotate(180, Vector3.up); rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, length - slabDepth)); // SLABS Mesh backSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth)); backSlab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, length - (slabDepth / 2))); Mesh frontSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth)); frontSlab.Translate(new Vector3((stepWidth + separation) / 2, y - slabThickness / 2, slabDepth / 2)); meshes.Add(leftFlight); meshes.Add(rightFlight); meshes.Add(backSlab); meshes.Add(frontSlab); Mesh combined = MeshX.Combine(meshes.ToArray()); return(combined); }
void OnValidate() { if (!Application.isPlaying) { return; } if (!stairWell) { if (!total) { gameObject.SetMesh(MeshX.Stairs(stairsNum, stepWidth, stepHeight, stepDepth)); } else { gameObject.SetMesh(MeshX.StairsBounds(stepWidth, totalHeight, totalDepth)); } } if (!stairWell) { return; } //floors = 1; if (floors < 1) { return; } Mesh combined = null; List <Mesh> meshes = new List <Mesh>(); float hH = floorHeight / 2; for (int f = 0; f < floors; f++) { float y = f * floorHeight; Mesh leftFlight = MeshX.StairsBounds(stepWidth, hH, totalDepth); Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, totalDepth); leftFlight.Translate(new Vector3(0, y)); rightFlight.Rotate(180, Vector3.up); rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, totalDepth)); float slabThickness = 0.3f; Mesh slab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth)); slab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, totalDepth + (slabDepth / 2))); meshes.Add(leftFlight); meshes.Add(rightFlight); meshes.Add(slab); } combined = MeshX.Combine(meshes.ToArray()); gameObject.SetMesh(combined); }
void Generate() { gameObject.InitializeMesh(null, null); List <Mesh> meshes = new List <Mesh>(); float totalHeight = floorHeight * floors; float totalX = xWidth * xNum; float totalZ = zWidth * zNum; Vector3 start = new Vector3(-xWidth / 2, 0, -zWidth / 2); Vector3 mid = new Vector3((-xWidth / 2) + xWidth * xNum / 2, 0, (-zWidth / 2) + zWidth * zNum / 2); // Columns for (int x = -1; x < xNum; x++) { for (int z = -1; z < zNum; z++) { Mesh column = MeshX.Cube(new Vector3(columnWidth, totalHeight - floorHeight, columnWidth)); column.Translate(-start + new Vector3(x * xWidth + xWidth / 2, (totalHeight - floorHeight) / 2, z * zWidth + zWidth / 2)); meshes.Add(column); } } for (int f = 0; f < floors; f++) { float y = f * floorHeight; // Slab for (int x = 0; x < xNum; x++) { for (int z = 0; z < zNum; z++) { if (x == stairWellX && z == stairWellZ) { continue; } Mesh slab = MeshX.Cube(new Vector3(xWidth, slabThickness, zWidth)); slab.Translate(-start + new Vector3(x * xWidth, y - slabThickness * 0.5f, z * zWidth)); meshes.Add(slab); } } // Parapet if (f > 0) { Mesh parapetUp = MeshX.Cube(new Vector3(totalX, parapetHeight, parapetWidth)); Mesh parapetDown = MeshX.Cube(new Vector3(totalX, parapetHeight, parapetWidth)); Mesh parapetLeft = MeshX.Cube(new Vector3(parapetWidth, parapetHeight, totalZ)); Mesh parapetRight = MeshX.Cube(new Vector3(parapetWidth, parapetHeight, totalZ)); parapetUp.Translate(-start + mid + new Vector3(0, y, totalZ / 2)); parapetDown.Translate(-start + mid + new Vector3(0, y, -totalZ / 2)); parapetLeft.Translate(-start + mid + new Vector3(-totalX / 2, y, 0)); parapetRight.Translate(-start + mid + new Vector3(+totalX / 2, y, 0)); meshes.Add(parapetUp); meshes.Add(parapetDown); meshes.Add(parapetLeft); meshes.Add(parapetRight); } // Stairs if (f == floors - 1) { continue; } float stairSeparation = xWidth - 1.2f * 2; Mesh stairs = MeshXBuildings.Stairwell(1.2f, zWidth, floorHeight, 1.2f, stairSeparation, slabThickness); stairs.Translate(new Vector3(stairWellX * xWidth + 0.6f, y, stairWellZ * zWidth)); meshes.Add(stairs); } gameObject.SetMesh(MeshX.Combine(meshes.ToArray())); }