/// <summary> /// Extrude the window on the middle of the wall /// </summary> /// <param name="plan">Apartment plan</param> public void Extrude(Plan plan) { windowPrefab = LoadWindowPrefab(); GameObject window = ExtrusionUtils.InstanciateComponent(windowPrefab, new Vector3(start[0], start[1]), new Vector3(stop[0], stop[1]), plan.wallHeight - plan.windowH1 - plan.windowH2, "Window", "window", 9);; window.transform.position += new Vector3(0, plan.windowH1, 0); window.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); Vector3 windowPos = window.transform.position; BoxCollider boxCollider = window.AddComponent <BoxCollider>(); windowsCollider.Add(boxCollider); boxCollider.size = new Vector3(1, 1, 2); boxCollider.center = new Vector3(0, plan.windowH1 / 2, 0); GameObject curtain = ExtrusionUtils.InstanciateComponent(curtainPrefab, new Vector3(start[0], start[1]), new Vector3(stop[0], stop[1]), plan.wallHeight, "Window", "curtain", 9); curtain.transform.position += new Vector3(0, plan.windowH1 + (plan.windowH2 - plan.windowH1) / 2 + 0.6f, 0f); curtain.transform.localScale += new Vector3(0, -0.6f, 0); float wallOffset = 0f; if (Math.Abs(stop[0] - start[0]) == 0) { wallOffset = 0.2f + 0.4f * Math.Abs(stop[1] - start[1]); } else if (Math.Abs(stop[1] - start[1]) == 0) { wallOffset = 0.2f + 0.4f * Math.Abs(stop[0] - start[0]); } PlaceCurtains(curtain, plan, wallOffset); }
/// <summary> /// Create an edge of a wall /// </summary> /// <param name="prefab">GameObject prefab to instanciate</param> /// <param name="pos">Position of the edge to instanciate</param> /// <param name="height">Height of the edge</param> /// <param name="width">Width of the edge</param> /// <param name="tag">Tag to edge to instanciate</param> /// <param name="name">Name of the edge to instanciate</param> /// <param name="layer">Layer of the edge to instanciate</param> public static void InstanciateEdge(GameObject prefab, Vector3 pos, float height, float width, string name, string tag = "Wall", int layer = 10) { GameObject edge = ExtrusionUtils.InstanciateComponent(prefab, pos, pos, height, "Wall", name, 10); edge.transform.position += new Vector3(0, height / 2, 0); edge.transform.localScale += new Vector3(width, 0, width); edge.GetComponent <MeshRenderer>().material.mainTextureScale = new Vector2(width, height); }
/// <summary> /// Extrude the wall above the door, extrude the door and add the collider to the door, the collider is added for the furniture placement /// </summary> /// <param name="plan"></param> public void Extrude(Plan plan) { GameObject doorWall = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(start[0], start[1]), new Vector3(stop[0], stop[1]), plan.doorH2, "Door", name + "_up", 8); doorWall.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); doorWall.transform.position += new Vector3(0, plan.wallHeight - (plan.doorH2 / 2), 0); GameObject doorObject = ExtrusionUtils.InstanciateComponent(doorPrefab, new Vector3(start[0], start[1]), new Vector3(stop[0], stop[1]), 1, "Door", name, 8); float xOffset = Math.Abs(start[0] - stop[0]); float zOffset = Math.Abs(start[1] - stop[1]); if (xOffset == 0) { doorObject.transform.localScale += new Vector3(0, 0, zOffset - DOOR_WIDTH_OFFSET); } else if (zOffset == 0) { doorObject.transform.localScale += new Vector3(0, 0, xOffset - DOOR_WIDTH_OFFSET); } // Add the collider to doors BoxCollider boxCollider = doorObject.AddComponent <BoxCollider>(); doorsCollider.Add(boxCollider); if (doorObject.transform.eulerAngles.y == 0) { boxCollider.size = new Vector3(1, plan.wallHeight, 1.5f); boxCollider.center = new Vector3(0, plan.wallHeight / 2, 0); } else { boxCollider.size = new Vector3(1.5f, plan.wallHeight, 1); boxCollider.center = new Vector3(0, plan.wallHeight / 2, 0); } //Allows to block the front door if (isFrontDoor) { GameObject.Destroy(doorObject.GetComponent <OpenDoor>()); doorObject.layer = LayerMask.NameToLayer("FrontDoor"); //Add layer to children object door foreach (Transform child in doorObject.transform) { if (child == null) { continue; } child.gameObject.layer = 18; } } }
/// <summary> /// Extrude the wall of the apartment, Build a single wall if there is no window, otherwise build 4 walls to place the window and create the window /// </summary> /// <param name="plan">Plan apartment</param> public void Extrude(Plan plan) { if (window.start == null) { GameObject wall = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(start[0], start[1]), new Vector3(stop[0], stop[1]), plan.wallHeight, "Wall", name, 10); wall.transform.position += new Vector3(0, plan.wallHeight / 2, 0); wall.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(start[0], start[1]), plan.wallHeight, plan.wallWidth, name + "_edge_left"); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(stop[0], stop[1]), plan.wallHeight, plan.wallWidth, name + "_edge_right"); } else { GameObject wallLeft = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(start[0], start[1]), new Vector3(window.start[0], window.start[1]), plan.wallHeight, "Wall", name + "_left", 10); wallLeft.transform.position += new Vector3(0, plan.wallHeight / 2, 0); wallLeft.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); GameObject wallRight = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(window.stop[0], window.stop[1]), new Vector3(stop[0], stop[1]), plan.wallHeight, "Wall", name + "_right", 10); wallRight.transform.position += new Vector3(0, plan.wallHeight / 2, 0); wallRight.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); GameObject wallUp = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(window.start[0], window.start[1]), new Vector3(window.stop[0], window.stop[1]), plan.windowH2, "Wall", name + "_up", 10); wallUp.transform.position += new Vector3(0, plan.wallHeight - (plan.windowH2 / 2), 0); wallUp.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); GameObject wallDown = ExtrusionUtils.InstanciateComponent(wallPrefab, new Vector3(window.start[0], window.start[1]), new Vector3(window.stop[0], window.stop[1]), plan.windowH1, "Wall", name + "_down", 10); wallDown.transform.position += new Vector3(0, plan.windowH1 / 2, 0); wallDown.transform.localScale += new Vector3(-plan.wallWidth, 0, plan.wallWidth); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(start[0], start[1]), plan.wallHeight, plan.wallWidth, name + "_edge_left"); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(window.start[0], window.start[1]), plan.wallHeight, plan.wallWidth, name + "_edge_center_left"); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(window.stop[0], window.stop[1]), plan.wallHeight, plan.wallWidth, name + "_edge_center_right"); ExtrusionUtils.InstanciateEdge(wallPrefab, new Vector3(stop[0], stop[1]), plan.wallHeight, plan.wallWidth, name + "_edge_right"); window.Extrude(plan); } }