public override void EmitMarkers(DungeonBuilder builder) { var model = builder.Model as GridDungeonModel; if (model == null) { return; } var config = model.Config as GridDungeonConfig; if (config == null) { return; } var cellSize = config.GridCellSize; foreach (var cell in model.Cells) { var bounds = cell.Bounds; var cx = (bounds.Location.x + bounds.Size.x / 2.0f) * cellSize.x; var cy = bounds.Location.y * cellSize.y; var cz = (bounds.Location.z + bounds.Size.z / 2.0f) * cellSize.z; var position = new Vector3(cx, cy, cz); var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one); var markerName = (cell.CellType == CellType.Room) ? "RoomCenter" : "CorridorCenter"; builder.EmitMarker(markerName, transform, cell.Bounds.Location, cell.Id); } }
public override void EmitMarkers(DungeonBuilder builder) { var gridModel = builder.Model as GridDungeonModel; if (gridModel == null) { Debug.LogWarning("invalid builder used with this marker emitter"); return; } var config = gridModel.Config; var gridSize = config.GridCellSize; var wall2DMarkers = new List <Wall2DMarkerInfo>(); var occupied = new Dictionary <string, HashSet <IntVector> >(); foreach (var prop in builder.PropSockets) { if (prop.SocketType == DungeonConstants.ST_WALL) { var markerInfo = GetMarker2D(prop, DungeonConstants.ST_WALL2D, gridSize); RegisterMarker(markerInfo, wall2DMarkers, occupied); } else if (prop.SocketType == DungeonConstants.ST_FENCE) { var markerInfo = GetMarker2D(prop, DungeonConstants.ST_WALL2D, gridSize); RegisterMarker(markerInfo, wall2DMarkers, occupied); } else if (prop.SocketType == DungeonConstants.ST_DOOR) { var rotation = Matrix.GetRotation(ref prop.Transform); var angleStep = (Mathf.RoundToInt(rotation.eulerAngles.y / 90.0f) + 4) % 4; var doorMarker = DungeonConstants.ST_DOOR2D; if (angleStep == 1 || angleStep == 3) { // Angle is 90 or 270 doorMarker = DungeonConstants.ST_DOOR2D_90; } var markerInfo = GetMarker2D(prop, doorMarker, gridSize); RegisterMarker(markerInfo, wall2DMarkers, occupied); } } // fix the corners if (fixCorners) { FixCornerWalls(wall2DMarkers, builder.PropSockets, occupied, gridSize); } { // Add Ground2d markers. These are the same as ground markers, except that are not placed over 2d walls AddGround2DMarkers(wall2DMarkers, occupied, builder.PropSockets, gridSize); } foreach (var markerInfo in wall2DMarkers) { builder.EmitMarker(markerInfo.markerName, markerInfo.transform, markerInfo.gridPosition, markerInfo.cellId); } }
void EmitChunkMarker(DungeonBuilder builder, string markerName, Vector3 gridPositionF, float angle, Vector3 gridSize, int cellId) { var worldPosition = Vector3.Scale(gridPositionF, gridSize); var matrix = Matrix4x4.TRS(worldPosition, Quaternion.Euler(0, angle, 0), Vector3.one); var gridPosition = new IntVector(gridPositionF); builder.EmitMarker(markerName, matrix, gridPosition, cellId); }
void EmitGroundMarker(DungeonBuilder builder, int sizeX, int sizeZ, Vector3 cellSize) { var position = Vector3.Scale(new Vector3(sizeX, 0, sizeZ) / 2.0f, cellSize) + transform.position; var scale = new Vector3(sizeX, 1, sizeZ); var trans = Matrix4x4.TRS(position, Quaternion.identity, scale); builder.EmitMarker(GroundMarkerName, trans, IntVector.Zero, -1); }
void EmitMarkerAt(DungeonBuilder builder, Vector3 cellSize, string markerName, float x, float z, float angle) { var worldPosition = Vector3.Scale(new Vector3(x, 0, z), cellSize) + transform.position; var rotation = Quaternion.Euler(0, angle, 0); var transformation = Matrix4x4.TRS(worldPosition, rotation, Vector3.one); var gridPosition = new IntVector((int)x, 0, (int)z); // Optionally provide where this marker is in the grid position builder.EmitMarker(markerName, transformation, gridPosition, -1); }
void EmitCornerMarker(DungeonBuilder builder, GridDungeonModel model, IntVector point, string markerName) { // Add an empty marker here var gridSize = model.Config.GridCellSize; var position = point * gridSize; position += Vector3.Scale(new Vector3(0.5f, 0, 0.5f), gridSize); var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one); builder.EmitMarker(markerName, transform, point, -1); }
void EmitCornerMarker(DungeonBuilder builder, GridDungeonModel model, IntVector point, float angleY, string markerName) { var gridSize = model.Config.GridCellSize; var position = point * gridSize; position += Vector3.Scale(new Vector3(0.5f, 0, 0.5f), gridSize); var rotation = Quaternion.Euler(0, angleY, 0); var transform = Matrix4x4.TRS(position, rotation, Vector3.one); builder.EmitMarker(markerName, transform, point, -1); }
public override void EmitMarkers(DungeonBuilder builder) { if (!(builder is GridDungeonBuilder)) { Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFindLowestPoint. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null")); return; } var gridModel = builder.Model as GridDungeonModel; var Min = new Vector3(int.MaxValue, int.MaxValue, int.MaxValue); var Max = new Vector3(-int.MaxValue, -int.MaxValue, -int.MaxValue); var gridSize = gridModel.Config.GridCellSize; if (gridModel.Cells.Count == 0) { Min = Vector3.zero; Max = Vector3.zero; } else { foreach (var cell in gridModel.Cells) { var location = cell.Bounds.Location * gridSize; var size = cell.Bounds.Size * gridSize; Min.x = Mathf.Min(Min.x, location.x); Min.y = Mathf.Min(Min.y, location.y); Min.z = Mathf.Min(Min.z, location.z); Max.x = Mathf.Max(Max.x, location.x + size.x); Max.y = Mathf.Max(Max.y, location.y + size.y); Max.z = Mathf.Max(Max.z, location.z + size.z); } } var rangeSize = Max - Min; var position = (Max + Min) / 2; position.y = Min.y; var scale = new Vector3(rangeSize.x, 1, rangeSize.z); var transform = Matrix4x4.TRS(position, Quaternion.identity, scale); builder.EmitMarker(MarkerName, transform, IntVector.Zero, -1); // Save this for other markers to use, if needed builder.Blackboard.FloatEntries.SetValue(BlackboardKeyLowestY, Min.y); }
public override void EmitMarkers(DungeonBuilder builder) { if (!(builder is GridDungeonBuilder)) { Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFreeSpaceDecorator. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null")); return; } var model = builder.Model as GridDungeonModel; var gridSize = model.Config.GridCellSize; var visited = new HashSet <IntVector>(); var occupied = new HashSet <IntVector>(); foreach (var cell in model.Cells) { if (cell.CellType == CellType.Unknown) { continue; } for (var distance = 2; distance <= 2; distance++) { var bounds = cell.Bounds; bounds = Rectangle.ExpandBounds(bounds, distance); var points = bounds.GetBorderPoints(); foreach (var point in points) { var hash = new IntVector(point.x, 0, point.z); if (!visited.Contains(hash)) { visited.Add(hash); if (occupied.Contains(hash)) { continue; } // Check if this point does not lie in a cell var cellInfo = model.GetGridCellLookup(point.x, point.z); if (cellInfo.CellType == CellType.Unknown) { // Make sure the surrounding area is free so we can place a decorative item bool valid = true; var s = distanceFromEdge - 1; for (var dx = -s; dx <= s; dx++) { for (var dz = -s; dz <= s; dz++) { var x = point.x + dx; var z = point.z + dz; var neighborHash = new IntVector(x, 0, z); if (occupied.Contains(neighborHash)) { valid = false; break; } var neighborCellInfo = model.GetGridCellLookup(x, z); if (neighborCellInfo.CellType != CellType.Unknown) { // Occupied by an existing cell occupied.Add(neighborHash); valid = false; break; } } if (!valid) { break; } } if (valid) { // Valid space. Occupy the space here for (var dx = -s; dx <= s; dx++) { for (var dz = -s; dz <= s; dz++) { var x = point.x + dx; var z = point.z + dz; occupied.Add(new IntVector(x, 0, z)); } } var pushDownY = 0.0f; foreach (var pushDownAxis in pushDownTestAxis) { var delta = pushDownAxis * distanceFromEdge; var x = point.x + Mathf.RoundToInt(delta.x); var z = point.z + Mathf.RoundToInt(delta.z); var testCellInfo = model.GetGridCellLookup(x, z); if (testCellInfo.CellType != CellType.Unknown) { pushDownY = pushDownAmount; } } var position = point * gridSize + new Vector3(gridSize.x, 0, gridSize.z) * 0.5f; position.y -= pushDownY; var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one); builder.EmitMarker(markerName, transform, point, -1); } } else { // Occupied by a cell occupied.Add(hash); } } } } } }
public override void EmitMarkers(DungeonBuilder builder) { var visited = new HashSet <IntVector>(); var model = builder.Model as GridDungeonModel; if (model == null) { return; } var config = model.Config as GridDungeonConfig; if (config == null) { return; } var gridSize = config.GridCellSize; float overrideYValue = 0; if (overrideY) { overrideYValue = builder.Blackboard.FloatEntries.GetValue(overrideYBlackboardKey); } for (int d = 1; d <= distanceToCover; d++) { var indexedMarkerName = indexedMarkerNamePrefix + d; foreach (var cell in model.Cells) { if (cell.CellType == CellType.Unknown) { continue; } var bounds = cell.Bounds; bounds = Rectangle.ExpandBounds(bounds, d); var points = bounds.GetBorderPoints(); foreach (var point in points) { var hash = new IntVector(point.x, 0, point.z); if (!visited.Contains(hash)) { // Check if this point does not lie in a cell var cellInfo = model.GetGridCellLookup(point.x, point.z); if (cellInfo.CellType == CellType.Unknown) { // Add an empty marker here var position = point * gridSize; position += Vector3.Scale(new Vector3(0.5f, 0, 0.5f), gridSize); if (overrideY) { position.y = overrideYValue; } var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one); builder.EmitMarker(markerName, transform, point, -1); builder.EmitMarker(indexedMarkerName, transform, point, -1); } visited.Add(hash); } } } } }