Created
March 30, 2017 04:12
-
-
Save coderespawn/e84903e5c2ba6bf8719e4a122adc126f to your computer and use it in GitHub Desktop.
Emits markers on the furthest rooms of the dungeon. You can then add these markers in your theme file and attach anything to it. More info here: https://youtu.be/FLEfDQiEWEc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using DungeonArchitect; | |
using DungeonArchitect.Builders.Grid; | |
public class FurthersRoomsMarkers : DungeonMarkerEmitter { | |
public string startMarker = "StartRoom"; | |
public string endMarker = "EndRoom"; | |
public override void EmitMarkers(DungeonBuilder builder) | |
{ | |
var gridModel = builder.Model as GridDungeonModel; | |
if (gridModel == null) { | |
// Can only be used with a grid dungeon | |
return; | |
} | |
var cellSize = gridModel.Config.GridCellSize; | |
var furthestCells = GridDungeonModelUtils.FindFurthestRooms(gridModel); | |
EmitMarkerOnCell(furthestCells[0], cellSize, builder, startMarker); | |
EmitMarkerOnCell(furthestCells[1], cellSize, builder, endMarker); | |
} | |
void EmitMarkerOnCell(Cell cell, Vector3 cellSize, DungeonBuilder builder, string markerName) | |
{ | |
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); | |
builder.EmitMarker(markerName, transform, cell.Bounds.Location, cell.Id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment