Skip to content

Instantly share code, notes, and snippets.

@AG-Dan
Last active May 10, 2022 15:22
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/7ec062b4937d66eb38bb0a8a0168c4e3 to your computer and use it in GitHub Desktop.
Save AG-Dan/7ec062b4937d66eb38bb0a8a0168c4e3 to your computer and use it in GitHub Desktop.
A script for programatically modifying the dungeon length. Just assign the correct RuntimeDungeon (also turn off 'Generate on Start') and call this script's Generate() method.
using DunGen;
using DunGen.Graph;
using UnityEngine;
public class ModifyDungeonLength : MonoBehaviour
{
public RuntimeDungeon DungeonGenerator;
public int MinLength = 5;
public int MaxLength = 10;
private DungeonFlow originalFlow;
private DungeonFlow modifiedFlow;
public void Generate()
{
// Keep a reference to the original flow asset
if (modifiedFlow == null)
{
originalFlow = DungeonGenerator.Generator.DungeonFlow;
// We make a copy of the dungeon flow before modifying any settings.
// If we just modify the original, we'd permanently change the settings
// on that asset in our project.
// NOTE: This has to be done for any asset we want to modify
// (anything derived from ScriptableObject such as tile sets and archetypes) to avoid changing the original
modifiedFlow = Instantiate(originalFlow);
}
// Change the length to whatever we want
modifiedFlow.Length.Min = MinLength;
modifiedFlow.Length.Max = MaxLength;
// Apply the modified flow and generate
DungeonGenerator.Generator.DungeonFlow = modifiedFlow;
DungeonGenerator.Generate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment