Skip to content

Instantly share code, notes, and snippets.

@AG-Dan
Last active June 26, 2021 11:27
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/b03702b4dc3d9ac017ed4e2897e25c6d to your computer and use it in GitHub Desktop.
Save AG-Dan/b03702b4dc3d9ac017ed4e2897e25c6d to your computer and use it in GitHub Desktop.
Uses the new API in DunGen 2.14 beta to force certain rooms to connect to oneanother via a specific doorway socket
using DunGen;
using DunGen.Tags;
using UnityEngine;
public class LargeRoomConnectionRule : MonoBehaviour
{
public DoorwaySocket LargeSocket = null;
public Tag LargeRoomTag;
private TileConnectionRule rule;
private void OnEnable()
{
rule = new TileConnectionRule(CanTilesConnect);
DoorwayPairFinder.CustomConnectionRules.Add(rule);
}
private void OnDisable()
{
DoorwayPairFinder.CustomConnectionRules.Remove(rule);
rule = null;
}
private TileConnectionRule.ConnectionResult CanTilesConnect(Tile tileA, Tile tileB, Doorway doorwayA, Doorway doorwayB)
{
// Check if the two tiles are large. This is using DunGen's tag system, but we could
// also check the tile names, or look for a specific component
bool tileAIsLarge = tileA.Tags.HasTag(LargeRoomTag);
bool tileBIsLarge = tileB.Tags.HasTag(LargeRoomTag);
// Are we interested in this connection?...
if (tileAIsLarge && tileBIsLarge)
{
// If both sockets are large, allow the connection, otherwise deny
if (doorwayA.Socket == doorwayB.Socket && doorwayA.Socket == LargeSocket)
return TileConnectionRule.ConnectionResult.Allow;
else
return TileConnectionRule.ConnectionResult.Deny;
}
// ...if not, pass it on to be handled later
else
return TileConnectionRule.ConnectionResult.Passthrough;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment