public Vector3 CreateFloor(Vector3 position) { GenerateFloor(); floor = this.transform.Find("Floor").gameObject; floorAddOns = this.transform.Find("FloorAddOns").gameObject; parentInfo = this.transform.parent.GetComponent <Building>(); floor.GetComponent <MeshRenderer>().material = this.transform.parent.GetComponent <Building>().chosenMat; Vector3 point = position; MeshOps.CreateParall(point, parentInfo.width, this.floorHeight, parentInfo.depth, vertexList, triangleList, uvList); CreateWindows(point, position.y, this.floorNumber, parentInfo.width, parentInfo.depth); point = new Vector3(point.x, position.y + this.floorHeight, point.z); if (parentInfo.separatorList[this.floorNumber]) { //create separator MeshOps.CreateParall(point, parentInfo.width + this.separatorOffset * 2, this.separatorHeight, parentInfo.depth + this.separatorOffset * 2, vertexList2, triangleList2, uvList2); point = new Vector3(position.x, point.y + this.separatorHeight, position.z); } if (this.floorNumber == this.transform.parent.GetComponent <Building>().floors - 1) { //CreateRoof if needed if (parentInfo.hasRoof) { CreateRoof(point); } } SetAndClearFloorMesh(); SetAndClearFloorAddOnsMesh(); if (floor.GetComponent <BoxCollider>() != null) { DestroyImmediate(floor.gameObject.GetComponent <BoxCollider>()); } if (floorAddOns.GetComponent <BoxCollider>() != null) { DestroyImmediate(floorAddOns.gameObject.GetComponent <BoxCollider>()); } floor.AddComponent <BoxCollider>(); floorAddOns.AddComponent <BoxCollider>(); return(point); }
public void CreateWindows(Vector3 position, float textCoord, int floorNumber, float width, float depth) { Vector3 point; if (this.floorNumber == parentInfo.floors) { return; } if (this.floorNumber == 0) //create door { point = new Vector3(position.x, position.y, position.z - depth / 2 - 0.01f); MeshOps.CreateParall(point, parentInfo.doorWidth, parentInfo.doorHeight, 0.3f, vertexList2, triangleList2, uvList2); return; } //create windows //front and back windows float winBox = Mathf.Min(this.windowBoxWidth, width); int winNumber = (int)Mathf.Floor(width / winBox); float winWidth = Mathf.Min(winBox - (0.1f * 2), this.windowWidth); float winHeight = Mathf.Min(this.windowHeight, this.floorHeight - 0.2f); float winDepth = 0.03f; float offset = width / winNumber; for (int i = 0; i < winNumber; i++) { //CreateBalcony if (this.frontWindows[i]) { var balconyWidth = winWidth + 0.3f; point = new Vector3(position.x - width / 2 + offset * i + (offset / 2), position.y + 0.05f, position.z - depth / 2 - 0.4f); MeshOps.CreateParall(point, balconyWidth, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //front var newPoint = new Vector3(point.x, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, balconyWidth, 0.1f, 0.5f, vertexList2, triangleList2, uvList2); //bottom newPoint = new Vector3(point.x - balconyWidth / 2, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, 0.5f, vertexList2, triangleList2, uvList2); //left newPoint = new Vector3(point.x + balconyWidth / 2, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, 0.5f, vertexList2, triangleList2, uvList2); //right point = new Vector3(point.x, position.y + 0.05f, position.z - depth / 2 - 0.01f); MeshOps.CreateParall(point, winWidth, this.floorHeight - (this.floorHeight - winHeight) / 2 - 0.05f, winDepth, vertexList2, triangleList2, uvList2); //window } else { point = new Vector3(position.x - width / 2 + offset * i + (offset / 2), position.y + (this.floorHeight - winHeight) / 2, position.z - depth / 2 - 0.01f); MeshOps.CreateParall(point, winWidth, winHeight, winDepth, vertexList2, triangleList2, uvList2); } if (this.backWindows[i]) { var balconyWidth = winWidth + 0.3f; point = new Vector3(position.x - width / 2 + offset * i + (offset / 2), position.y + 0.05f, position.z + depth / 2); var newPoint = new Vector3(point.x, point.y, point.z + 0.4f); MeshOps.CreateParall(newPoint, balconyWidth, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //front newPoint = new Vector3(point.x, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, balconyWidth, 0.1f, 0.5f, vertexList2, triangleList2, uvList2); //bottom newPoint = new Vector3(point.x - balconyWidth / 2, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, 0.5f, vertexList2, triangleList2, uvList2); //left side newPoint = new Vector3(point.x + balconyWidth / 2, point.y, point.z + 0.2f); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, 0.5f, vertexList2, triangleList2, uvList2); //right side point = new Vector3(point.x, position.y + 0.05f, position.z + depth / 2 + 0.01f); MeshOps.CreateParall(point, winWidth, this.floorHeight - (this.floorHeight - winHeight) / 2 - 0.05f, winDepth, vertexList2, triangleList2, uvList2); //window } else { point = new Vector3(position.x - width / 2 + offset * i + (offset / 2), position.y + (this.floorHeight - winHeight) / 2, position.z + depth / 2 + 0.01f); MeshOps.CreateParall(point, winWidth, winHeight, winDepth, vertexList2, triangleList2, uvList2); } } //side windows float sideWinBox = Mathf.Min(this.sideWinBoxWidth, depth); int sideWinNumber = (int)Mathf.Floor(depth / sideWinBox); winWidth = Mathf.Min(sideWinBox - (0.1f * 2), this.sideWindowWidth); winHeight = Mathf.Min(this.sideWindowHeight, this.floorHeight - 0.2f); winDepth = 0.03f; offset = depth / sideWinNumber; for (int i = 0; i < sideWinNumber; i++) { //CreateBalcony if (this.leftWindows[i]) { var balconyWidth = winWidth + 0.3f; point = new Vector3(position.x - width / 2, position.y + 0.05f, position.z - depth / 2 + offset * i + (offset / 2)); var newPoint = new Vector3(point.x - 0.4f, point.y, point.z); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, balconyWidth, vertexList2, triangleList2, uvList2); //front newPoint = new Vector3(point.x - 0.2f, point.y, point.z); MeshOps.CreateParall(newPoint, 0.5f, 0.1f, balconyWidth, vertexList2, triangleList2, uvList2); //bottom newPoint = new Vector3(point.x - 0.2f, point.y, point.z + balconyWidth / 2); MeshOps.CreateParall(newPoint, 0.5f, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //left newPoint = new Vector3(point.x - 0.2f, point.y, point.z - balconyWidth / 2); MeshOps.CreateParall(newPoint, 0.5f, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //right point = new Vector3(point.x - 0.01f, position.y + 0.05f, point.z); MeshOps.CreateParall(point, winDepth, this.floorHeight - (this.floorHeight - winHeight) / 2 - 0.05f, winWidth, vertexList2, triangleList2, uvList2); //window } else { point = new Vector3(position.x - width / 2 - 0.01f, position.y + (this.floorHeight - winHeight) / 2, position.z - depth / 2 + offset * i + (offset / 2)); MeshOps.CreateParall(point, winDepth, winHeight, winWidth, vertexList2, triangleList2, uvList2); } if (this.rightWindows[i]) { var balconyWidth = winWidth + 0.3f; point = new Vector3(position.x + width / 2, position.y + 0.05f, position.z - depth / 2 + offset * i + (offset / 2)); var newPoint = new Vector3(point.x + 0.4f, point.y, point.z); MeshOps.CreateParall(newPoint, 0.1f, 0.4f, balconyWidth, vertexList2, triangleList2, uvList2); //front newPoint = new Vector3(point.x + 0.2f, point.y, point.z); MeshOps.CreateParall(newPoint, 0.5f, 0.1f, balconyWidth, vertexList2, triangleList2, uvList2); //bottom newPoint = new Vector3(point.x + 0.2f, point.y, point.z - balconyWidth / 2); MeshOps.CreateParall(newPoint, 0.5f, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //left newPoint = new Vector3(point.x + 0.2f, point.y, point.z + balconyWidth / 2); MeshOps.CreateParall(newPoint, 0.5f, 0.4f, 0.1f, vertexList2, triangleList2, uvList2); //right point = new Vector3(point.x + 0.01f, position.y + 0.05f, point.z); MeshOps.CreateParall(point, winDepth, this.floorHeight - (this.floorHeight - winHeight) / 2 - 0.05f, winWidth, vertexList2, triangleList2, uvList2); //window } else { point = new Vector3(position.x + width / 2 + 0.01f, position.y + (this.floorHeight - winHeight) / 2, position.z - depth / 2 + offset * i + (offset / 2)); MeshOps.CreateParall(point, winDepth, winHeight, winWidth, vertexList2, triangleList2, uvList2); } } }
public void CreateRoof(Vector3 position) { float rLowWidth; if ((parentInfo.roofLowWidth - parentInfo.width) < 0) { rLowWidth = parentInfo.width; } else { rLowWidth = parentInfo.roofLowWidth; } float rUpWidth = Mathf.Min(rLowWidth, parentInfo.roofUpWidth); float rDepth; if ((parentInfo.roofDepth - parentInfo.depth) < 0) { rDepth = parentInfo.depth; } else { rDepth = parentInfo.roofDepth; } var offsetLowX = (rLowWidth - parentInfo.width) / 2; var offsetUpX = (parentInfo.width - rUpWidth) / 2; var offsetZ = (rDepth - parentInfo.depth) / 2; //build classic roof if (floorNumber <= 3) { //front vertexList.Add(new Vector3(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top left vertexList.Add(new Vector3(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top right vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //bot left vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //bot right MeshOps.AddQuad(vertexList, triangleList); uvList.Add(new Vector2(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight)); //top left uvList.Add(new Vector2(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight)); //top right uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //bot left uvList.Add(new Vector2(position.x + parentInfo.width / 2 + offsetLowX, position.y)); //bot right //back vertexList.Add(new Vector3(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top right vertexList.Add(new Vector3(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top left vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot right vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot left MeshOps.AddQuad(vertexList, triangleList); uvList.Add(new Vector2(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight)); //top right uvList.Add(new Vector2(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight)); //top left uvList.Add(new Vector2(position.x + parentInfo.width / 2 + offsetLowX, position.y)); //bot right uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //bot left //left side vertexList.Add(new Vector3(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //bot right vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot left MeshOps.AddTriangle(vertexList, triangleList); uvList.Add(new Vector2(position.x - parentInfo.width / 2 + offsetUpX, position.y + parentInfo.roofHeight)); //top right uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //top left uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //bot left //right side vertexList.Add(new Vector3(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight, position.z)); //top right vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot right vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //bot left MeshOps.AddTriangle(vertexList, triangleList); uvList.Add(new Vector2(position.x + parentInfo.width / 2 - offsetUpX, position.y + parentInfo.roofHeight)); //top right uvList.Add(new Vector2(position.x + parentInfo.width / 2 + offsetLowX, position.y)); //top left uvList.Add(new Vector2(position.x + parentInfo.width / 2 - offsetLowX, position.y)); //bot left //bottom vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //top left vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z - parentInfo.depth / 2 - offsetZ)); //top right vertexList.Add(new Vector3(position.x - parentInfo.width / 2 - offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot left vertexList.Add(new Vector3(position.x + parentInfo.width / 2 + offsetLowX, position.y, position.z + parentInfo.depth / 2 + offsetZ)); //bot right MeshOps.AddQuad(vertexList, triangleList); uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //top left uvList.Add(new Vector2(position.x + parentInfo.width / 2 + offsetLowX, position.y)); //top right uvList.Add(new Vector2(position.x - parentInfo.width / 2 - offsetLowX, position.y)); //bot left uvList.Add(new Vector2(position.x + parentInfo.width / 2 + offsetLowX, position.y)); //bot right } //build skyscraper roof else { Vector3 point; //square empty in the middle if (parentInfo.roofType == 1) { if (offsetZ <= 0.1f) { rDepth = rDepth - offsetZ * 2 + 0.4f; offsetZ = 0.2f; } if (offsetLowX <= 0.1f) { rLowWidth = rLowWidth - offsetLowX * 2 + 0.4f; offsetLowX = 0.2f; } point = new Vector3(position.x, position.y, position.z - parentInfo.depth / 2); MeshOps.CreateParall(point, Mathf.Min(rLowWidth, parentInfo.width * 11 / 10), 0.4f, offsetZ * 2, vertexList, triangleList, uvList); //front point = new Vector3(position.x, position.y, position.z + parentInfo.depth / 2); MeshOps.CreateParall(point, Mathf.Min(rLowWidth, parentInfo.width * 11 / 10), 0.4f, offsetZ * 2, vertexList, triangleList, uvList); //back point = new Vector3(position.x - parentInfo.width / 2, position.y, position.z); MeshOps.CreateParall(point, 2 * offsetLowX, 0.4f, Mathf.Min(rDepth, parentInfo.depth * 11 / 10), vertexList, triangleList, uvList); //left point = new Vector3(position.x + parentInfo.width / 2, position.y, position.z); MeshOps.CreateParall(point, 2 * offsetLowX, 0.4f, Mathf.Min(rDepth, parentInfo.depth * 11 / 10), vertexList, triangleList, uvList); } //single big square else { MeshOps.CreateParall(position, rLowWidth, 0.4f, rDepth, vertexList2, triangleList2, uvList2); } } }