Engine.Map = Engine.designer.CreateMap([positionX = 0f, positionZ = 0f]);
Building building = Engine.designer.AddBuilding(Engine.Map, [positionX = 0f, positionZ = 0f, elevation = 0f]);
Or add it with a story
Building building = Engine.designer.AddBuildingWithStory(Engine.Map, storyWidth, storyHeight, floorHeight, [positionX = 0f, positionZ = 0f, elevation = 0f, roofStyleName = ""]);
Engine.designer.RemoveBuilding(building);
Story story = Engine.designer.AddStory(building, width, height, floorHeight, [positionX = 0f, positionY = 0f, positionZ = 0f, roofStyleName = ""]);
Engine.designer.RemoveStory(story);
Room room = Engine.designer.AddRoom(story, width, height, [positionX = 0f, positionZ = 0f, wallMaterial = null, floorMaterial = null, ceilMaterial = null, wallU = 0f, wallV = 0f, floorU = 0f, floorV = 0f, ceilU = 0f, ceilV = 0f]);
This method automatically remove the corresponding wall in adjacent room. To get the nowall value to supply : if removing wall at NORTH, add 1. If removing wall at EAST, add 2, if removing wall at SOUTH, add 4, if removing wall at WEST, add 8. A room with all four walls have a nowall value of 0. A room without walls have a nowall value of 15 (1 + 2 + 4 + 8).
Engine.designer.ChangeWallsInRoom(room, nowall);
Same as above, but sustract the value to nowall instead of adding it.
Engine.designer.RemoveRoom(room);
A portal is described by its direction (the wall of the room where it's located), its position along the wall and its selected shape (ie door, window, hole, doorX2...). The room where it is created is the 'entry room'.
//First, calculate the position of the exit in Building Engine coordinates :
Vector3 exit = Engine.utils.GetPositionFromPortalExit(direction, position, entryRoom);
//Next, find the room at exit position :
Story exitStory = Engine.utils.FindStoryAtPosition(entryRoom.story.building.map, exit);
if (exitStory != null){
Room exitRoom = Engine.utils.FindRoomAtPosition(entryRoom.story.building.map, exit);
if(exitRoom !=null)
{
//Calculate the position of the portal in the exitRoom
float exitPosition = Engine.utils.GetPositionInExitRoom(direction, position, entryRoom, exitRoom);
//Verify that the portal is not too wide for the exitRoom
if (Engine.utils.IsPortalNotTooWideForExitRoom(direction, exitPosition, exitRoom, Engine.builder.architect.portalsInfos[selectedShape].width))
{
//create the portal
Portal portal = Engine.designer.AddPortalBetweenRooms(entryRoom.story.building, entryRoom, direction, position, Engine.builder.architect.portalsInfos[selectedShape], exitRoom, exitPosition);
}
}
}
If the design is safe, you can add the portal without verifications. No need to calculate the exit position nor the exitRoom as the method do it for you :
Portal portal = Engine.designer.AddPortalBetweenRooms(entryRoom.story.building, entryRoom, direction, position, Engine.builder.architect.portalsInfos[selectedShape], [exitRoom = null, exitPosition = -1]);
//First, calculate the position of the exit in Building Engine coordinates :
Vector3 exit = Engine.utils.GetPositionFromPortalExit(direction, position, entryRoom);
Story exitStory = Engine.utils.FindStoryAtPosition(entryRoom.story.building.map, exit);
if(exitStory == null)
{
//can the portal be drawn on a facade (ie none other facade block it)
if (Engine.utils.CanPortalBeDrawnOnFacade(entryRoom.story.building, entryRoom, direction, position, Engine.builder.architect.portalsInfos[selectedShape]))
{
//add the portal
Portal portal = Engine.designer.AddPortalToOutdoor(entryRoom.story.building, entryRoom, direction, position, Engine.builder.architect.portalsInfos[selectedShape]);
}
}
If the design is safe, you can add the portal without verifications :
Portal portal = Engine.designer.AddPortalToOutdoor(entryRoom.story.building, entryRoom, direction, position, Engine.builder.architect.portalsInfos[selectedShape]);
Engine.designer.RemovePortal(portal);
The entryRoom is the lower room. The exitRoom is the upper room.
//First we calculate the exit position
Vector3 exit = Engine.utils.GetPositionFromVerticalPortalExit(entryRoom);
//Getting the exitRoom
Story exitStory = Engine.utils.FindStoryAtPosition(entryRoom.story.building.map, exit);
if(exitStory != null)
{
Room exitRoom = Engine.utils.FindRoomAtPosition(exitStory, exit);
if(entryRoom != null)
{
//check if the portal can be drawn in the exit room floor
Rect plane = new Rect();
plane.x = exitRoom.positionX + exitStory.positionX;
plane.width = exitRoom.width;
plane.y = exitRoom.positionZ + exitStory.positionZ;
plane.height = exitRoom.height;
Rect hole = new Rect();
hole.x = room.positionX + room.story.positionX;
hole.width = room.width;
hole.y = room.positionZ + room.story.positionZ;
hole.height = room.height;
if (Engine.utils.IsRect1ContainsRect2(plane, hole))
{
//adding the vertical portal
VerticalPortal verticalPortal = Engine.designer.AddVerticalPortal(entryRoom.story.building, entryRoom, Engine.builder.architect.GetStoryHeight(entryRoom.story), exitRoom);
}
}
}
If the design is safe, you can add the vertical portal without verifications. No need to find the exitRoom as the method find it for you :
VerticalPortal verticalPortal = Engine.designer.AddVerticalPortal(entryRoom.story.building, entryRoom, Engine.builder.architect.GetStoryHeight(entryRoom.story), [exitRoom = null]);
Engine.designer.RemoveVerticalPortal(verticalPortal);
Prop prop = Engine.designer.AddPropToMap(Engine.Map, propName, positionX, positionY, positionZ, rotation);
Engine.designer.RemovePropFromMap(Engine.Map, prop);
Prop prop = Engine.designer.AddPropToBuilding(building, propName, positionX, positionY, positionZ, rotation);
Engine.designer.RemovePropFromBuilding(building, prop);
Prop prop = Engine.designer.AddPropToStory(story, propName, positionX, positionY, positionZ, rotation);
Engine.designer.RemovePropFromStory(story, prop);
Prop prop = Engine.designer.AddPropToRoom(room, propName, positionX, positionY, positionZ, rotation);
Engine.designer.RemovePropFromRoom(room, prop);
Prop prop = Engine.designer.AddPropToPortal(portal, propName, positionX, positionY, positionZ, rotation);
Engine.designer.RemovePropFromPortal(portal, prop);
Prop prop = Engine.designer.AddPropToVerticalPortal(verticalPortal, propName, positionX, positionY, positionZ, rotation);
string s = Engine.encoder.EncodeMapToXML(Engine.Map).OuterXml;
if (!AssetDatabase.IsValidFolder("Assets/saves")) AssetDatabase.CreateFolder("Assets", "saves");
File.WriteAllText(Application.dataPath + "/saves/" + assetName + ".xml", s);
AssetDatabase.Refresh();
string s = File.ReadAllText("Assets/saves/" + assetPath + ".xml");
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlElement mapXML = doc.DocumentElement;
Engine.Map = Engine.decoder.DecodeToMap(mapXML);
//recalculate buildings, stories, rooms, poratls and vertical portals indexes
Engine.designer.SetHigherIndexes(Engine.Map);
Engine.Build(Engine.Map);
© 2017 Magyc Pixel. All rights reserved | Design by W3layouts