Skip to content

Instantly share code, notes, and snippets.

@AG-Dan
Created May 19, 2021 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AG-Dan/1017acfdff89954c525ec8f6c9e672b9 to your computer and use it in GitHub Desktop.
Save AG-Dan/1017acfdff89954c525ec8f6c9e672b9 to your computer and use it in GitHub Desktop.
Some examples of how we can use the placement information embedded in tiles. Each tile also has a 'Dungeon' property which has even more connectivity information including: lists for main path, branch path, and all tiles; as well as a list of all connections between tiles.
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using DunGen;
public static class ConnectivityFunctions
{
public static void GetPreviousAndNextTiles(Tile tile, out Tile previousTile, out Tile nextTile)
{
previousTile = null;
nextTile = null;
// NormalizedDepth gives us a value between 0-1 for how deep the tile is
// this is the distance along the main path if the tile is on the main path,
// or the distance along its branch otherwise
float currentTileDepth = tile.Placement.NormalizedDepth;
foreach(var doorway in tile.UsedDoorways)
{
var neighbour = doorway.ConnectedDoorway.Tile;
float neighbourTileDepth = neighbour.Placement.NormalizedDepth;
if (neighbourTileDepth < currentTileDepth)
previousTile = neighbour;
else if (neighbourTileDepth > currentTileDepth)
nextTile = neighbour;
}
}
public static IEnumerable<Tile> GetAdjacentTiles(Tile tile)
{
var neighbours = new List<Tile>();
// We can get this tile's neighbours by looking at all
// of the used doorways
foreach (var doorway in tile.UsedDoorways)
neighbours.Add(doorway.ConnectedDoorway.Tile);
return neighbours;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment