public static void CopyTiles(List <Tilemap> sourceTilemaps, List <Tilemap> destinationTilemaps, Vector3Int offset) { sourceTilemaps = RoomTemplateUtils.GetTilemapsForCopying(sourceTilemaps); DeleteNonNullTiles(sourceTilemaps, destinationTilemaps, offset); foreach (var sourceTilemap in sourceTilemaps) { var destinationTilemap = destinationTilemaps.FirstOrDefault(x => x.name == sourceTilemap.name); if (destinationTilemap == null) { continue; } foreach (var tilemapPosition in sourceTilemap.cellBounds.allPositionsWithin) { var tile = sourceTilemap.GetTile(tilemapPosition); if (tile != null) { destinationTilemap.SetTile(tilemapPosition + offset, tile); } } } }
public Polygon2D GetRoomTemplateOutline() { var tilemaps = RoomTemplateUtils.GetTilemaps(gameObject); var outlineTilemaps = RoomTemplateUtils.GetTilemapsForOutline(tilemaps); var usedTiles = RoomTemplateUtils.GetUsedTiles(outlineTilemaps); if (usedTiles.Count == 0) { return(null); } var minX = usedTiles.Min(x => x.x); var maxX = usedTiles.Max(x => x.x); var minY = usedTiles.Min(x => x.y); var maxY = usedTiles.Max(x => x.y) + PaddingTop; var polygonPoints = new List <Vector2Int>() { new Vector2Int(minX, minY), new Vector2Int(minX, maxY), new Vector2Int(maxX, maxY), new Vector2Int(maxX, minY), }; return(new Polygon2D(polygonPoints)); }
/// <summary> /// Disables colliders of individual room template tilemaps in the generated level. /// The goal is to try to keep triggers functioning. /// </summary> /// <param name="level"></param> public static void DisableRoomTemplatesColliders(GeneratedLevel level) { // Iterate through all the rooms foreach (var roomInstance in level.GetRoomInstances()) { var roomTemplateInstance = roomInstance.RoomTemplateInstance; var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplateInstance); foreach (var tilemap in tilemaps) { // Iterate through all the colliders foreach (var collider in tilemap.GetComponents <Collider2D>()) { // If the collider is not used by composite collider and it is not a trigger, destroy it if (!collider.usedByComposite && !collider.isTrigger) { Destroy(collider); } else if (collider.usedByComposite) { // If the collider is used by composite but that composite does not exist or is not a trigger, destroy it if (collider.composite == null || !collider.composite.isTrigger) { Destroy(collider); } } } } } }
public static void CopyTilesToSharedTilemaps(GeneratedLevel level, RoomInstance roomInstance) { var destinationTilemaps = level.GetSharedTilemaps(); var sourceTilemaps = RoomTemplateUtils.GetTilemaps(roomInstance.RoomTemplateInstance); CopyTiles(sourceTilemaps, destinationTilemaps, roomInstance.Position); }
private void AssertTilemapLayerExists(string layerName) { var levelRoot = GetGeneratedLevelRoot(); var tilemaps = RoomTemplateUtils.GetTilemaps(levelRoot); var tilemapLayer = tilemaps.SingleOrDefault(x => x.name == layerName); Assert.IsNotNull(tilemapLayer); }
public static void DisableRoomTemplatesRenderers(GeneratedLevel level) { foreach (var roomInstance in level.GetRoomInstances()) { var roomTemplateInstance = roomInstance.RoomTemplateInstance; var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplateInstance); foreach (var tilemap in tilemaps) { var tilemapRenderer = tilemap.GetComponent <TilemapRenderer>(); Destroy(tilemapRenderer); } } }
public static void DisableRoomTemplatesColliders(GeneratedLevel level) { foreach (var roomInstance in level.GetRoomInstances()) { var roomTemplateInstance = roomInstance.RoomTemplateInstance; var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplateInstance); foreach (var tilemap in tilemaps) { var compositeCollider = tilemap.GetComponent <CompositeCollider2D>(); if (compositeCollider != null && !compositeCollider.isTrigger) { compositeCollider.enabled = false; } } } }
public override void Run(GeneratedLevel level, LevelDescription levelDescription) { foreach (var roomInstance in level.GetRoomInstances()) { var roomTemplateInstance = roomInstance.RoomTemplateInstance; // Find floor tilemap layer var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplateInstance); var floor = tilemaps.Single(x => x.name == "Floor").gameObject; // Add floor collider AddFloorCollider(floor); // Add the room manager component var roomManager = roomTemplateInstance.AddComponent <CurrentRoomDetectionRoomManager>(); roomManager.RoomInstance = roomInstance; // Add current room detection handler floor.AddComponent <CurrentRoomDetectionTriggerHandler>(); } }
public void OnSceneGUITest(SceneView sceneView) { if (target == null) { #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui -= OnSceneGUITest; #endif return; } if (PrefabStageUtility.GetCurrentPrefabStage() == null) { #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui -= OnSceneGUITest; #endif return; } try { var roomTemplate = (RoomTemplate)target; var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplate.gameObject); var polygon = RoomTemplatesLoader.GetPolygonFromTilemaps(tilemaps); var points = polygon.GetPoints(); Handles.color = Color.yellow; for (int i = 0; i < points.Count; i++) { var point1 = new Vector3(points[i].X, points[i].Y, -1); var point2 = new Vector3(points[(i + 1) % points.Count].X, points[(i + 1) % points.Count].Y, -1); // Handles.DrawLine(point1 + new Vector3(0.5f, 0.5f), point2 + new Vector3(0.5f, 0.5f)); DrawOutline(point1, point2, Color.green); } } catch (ArgumentException) { } }
/// <summary> /// Gets all the shared tilemaps. /// </summary> /// <returns></returns> public List <Tilemap> GetSharedTilemaps() { return(RoomTemplateUtils.GetTilemaps(RootGameObject)); }