Building Engine for Unity3D - Tiny house coding

3b.Create it with code (alternative option)

Copy and paste the following code in a new script named "TinyHouseCreator". Attach it to the camera.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BuildingEngine;

public class TinyHouseCreator : MonoBehaviour {
 public Material whiteWalls;
 public Material salmonWalls;
 public Material bathroomTiles;
 public Material parquet;
 public Material tiledFloor;
 public Material carpet;
 public Material blueCarpet;
 public Material redCarpet;

 private void OnGUI()
 {
  if (GUI.Button(new Rect(20, 20, 200, 20), "CREATE TINY HOUSE")) CreateTinyHouse();
 }

 private void CreateTinyHouse()
 {
  GameObject buildingEngine = GameObject.Find("BuildingEngine");
  if (buildingEngine == null) Debug.LogError("You need a buildingEngine prefab in the Hierarchy");
  //creating a new map
  Engine.Map = Engine.designer.CreateMap();
  //add a building
  if (Engine.Map.buildings == null) Engine.Map.buildings = new List<Building>();
  Building building = Engine.designer.AddBuilding(Engine.Map);
  building.facadeMat = whiteWalls;
  building.roofStyleName = "flatRoof";
  building.roofMat = whiteWalls;
  //adding S0
  Story S0 = Engine.designer.AddStory(building, 16f, 8f, Engine.builder.architect.floorHeight);
  //adding S1
  Story S1 = Engine.designer.AddStory(building, 16f, 8f, Engine.builder.architect.floorHeight, 0f, Engine.builder.architect.floorHeight);
  S1.facadeV = Engine.builder.architect.floorHeight;
  //adding rooms to the first floor (S0)
  //adding R0
  Room R0 = Engine.designer.AddRoom(S0, 6f, 8f, 0f, 0f, salmonWalls, blueCarpet, salmonWalls);
  //adding R1
  Room R1 = Engine.designer.AddRoom(S0, 4f, 4f, 6f, 0f, salmonWalls, parquet, salmonWalls);
  //adding R2
  Room R2 = Engine.designer.AddRoom(S0, 4f, 4f, 6f, 4f, salmonWalls, parquet, salmonWalls);
  //R1 and R2 are created, we can now remove the wall between the two
  //the parameter nowall of the room object tells whereas the walls of a room exist
  //a value of 0 means the room have the four walls
  //if we want remove the room at the NORTH direction, we add 1
  //if we want remove the room at the EAST direction, we add 2
  //if we want remove the room at the SOUTH direction, we add 4
   //if we want remove the room at the WEST direction, we add 8
  //for the room R1, we want to remove the wall at the SOUTH direction so the nowall value is 4
  //the designer changes the value for the room R1 and the room R2
  Engine.designer.ChangeWallsInRoom(R1, R1.nowall + 4);
  //alternativly, we can change the nowall value of the R2 room
  //Engine.compposer.ChangeWallsInRoom(R2, R2.nowall + 1)
  //adding R3
  Room R3 = Engine.designer.AddRoom(S0, 6f, 8f, 10f, 0f, salmonWalls, tiledFloor, salmonWalls);
  //Adding portals in first floor
  //portals need a direction value (ie the wall where the portal is located in the room)
  //NORTH : direction = 0;
  //EAST : direction = 1;
  //SOUTH : direction = 2;
  //WEST : direction = 3;
  //creating P0 : a windowX2 shape, at NORTH direction and position of 2
  Portal P0 = Engine.designer.AddPortalToOutdoor(building, R0, 0, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  //adding prop to portal
  Engine.designer.AddPropToPortal(P0, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  //creating other portal
  Portal P1 = Engine.designer.AddPortalBetweenRooms(building, R0, 1, 5f, Engine.builder.architect.GetPortalInfoByName("door"), R2);
  Engine.designer.AddPropToPortal(P1, "modernWoodDoor", 0f, 0f, 0f, 0f);
  Portal P2 = Engine.designer.AddPortalToOutdoor(building, R0, 2, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P2, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P3 = Engine.designer.AddPortalToOutdoor(building, R0, 3, 3f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P3, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P4 = Engine.designer.AddPortalToOutdoor(building, R2, 2, 1f, Engine.builder.architect.GetPortalInfoByName("door"));
  Engine.designer.AddPropToPortal(P4, "modernWoodDoor", 0f, 0f, 0f, 0f);
  Portal P5 = Engine.designer.AddPortalToOutdoor(building, R3, 0, 1.5f, Engine.builder.architect.GetPortalInfoByName("doorX2"));
  Engine.designer.AddPropToPortal(P5, "glassBlackMetalDoorX2", 0f, 0f, 0f, 0f);
  Portal P6 = Engine.designer.AddPortalToOutdoor(building, R3, 1, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P6, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P7 = Engine.designer.AddPortalToOutdoor(building, R3, 1, 5f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P7, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P8 = Engine.designer.AddPortalToOutdoor(building, R3, 2, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P8, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P9 = Engine.designer.AddPortalBetweenRooms(building, R3, 3, 5f, Engine.builder.architect.GetPortalInfoByName("door"), R2);
  Engine.designer.AddPropToPortal(P9, "modernWoodDoor", 0f, 0f, 0f, 0f);
  //creating the rooms in the second floor
  Room R4 = Engine.designer.AddRoom(S1, 6f, 4f, 0f, 0f, bathroomTiles, bathroomTiles, bathroomTiles);
  Room R5 = Engine.designer.AddRoom(S1, 6f, 4f, 0f, 4f, salmonWalls, redCarpet, salmonWalls);
  Room R6 = Engine.designer.AddRoom(S1, 4f, 8f, 6f, 0f, salmonWalls, parquet, salmonWalls);
  Room R7 = Engine.designer.AddRoom(S1, 6f, 8f, 10f, 0f, salmonWalls, carpet, salmonWalls);
  //adding portals to second floor
  Portal P10 = Engine.designer.AddPortalToOutdoor(building, R7, 0, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P10, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P11 = Engine.designer.AddPortalToOutdoor(building, R7, 1, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P11, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P12 = Engine.designer.AddPortalToOutdoor(building, R7, 1, 5f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P12, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P13 = Engine.designer.AddPortalBetweenRooms(building, R7, 3, 5f, Engine.builder.architect.GetPortalInfoByName("door"), R6);
  Engine.designer.AddPropToPortal(P13, "modernWoodDoor", 0f, 0f, 0f, 0f);
  Portal P14 = Engine.designer.AddPortalToOutdoor(building, R6, 0, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P14, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P15 = Engine.designer.AddPortalToOutdoor(building, R6, 2, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P15, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P16 = Engine.designer.AddPortalToOutdoor(building, R7, 2, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P16, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P17 = Engine.designer.AddPortalBetweenRooms(building, R5, 1, 1f, Engine.builder.architect.GetPortalInfoByName("door"), R6);
  Engine.designer.AddPropToPortal(P17, "modernWoodDoor", 0f, 0f, 0f, 0f);
  Portal P18 = Engine.designer.AddPortalToOutdoor(building, R5, 2, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P18, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P19 = Engine.designer.AddPortalToOutdoor(building, R5, 3, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P19, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P20 = Engine.designer.AddPortalToOutdoor(building, R4, 0, 2f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P20, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  Portal P21 = Engine.designer.AddPortalBetweenRooms(building, R4, 2, 2f, Engine.builder.architect.GetPortalInfoByName("door"), R5);
  Engine.designer.AddPropToPortal(P21, "modernWoodDoor", 0f, 0f, 0f, 0f);
  Portal P22 = Engine.designer.AddPortalToOutdoor(building, R4, 3, 1f, Engine.builder.architect.GetPortalInfoByName("windowX2"));
  Engine.designer.AddPropToPortal(P22, "BlackDoubleWindow", 0f, 0f, 0f, 0f);
  //adding the vertical portal
  VerticalPortal VP0 = Engine.designer.AddVerticalPortal(building, R1, Engine.builder.architect.floorHeight, R6);
  Engine.designer.AddPropToVerticalPortal(VP0, "stairU", 0f, 0f, 0f, 0f);
  //building the map
  Engine.Build(Engine.Map);
 }
}

Hit the "PLAY" button. Hit the "Create tiny house" button. The tiny house is created from the code above.

Next >>

© 2017 Magyc Pixel. All rights reserved | Design by W3layouts