-
-
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
This file contains 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 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