Created
November 15, 2016 15:39
-
-
Save AG-Dan/dcb86dfca4d59ba96281d8390d81a52a to your computer and use it in GitHub Desktop.
Attempt at creating dungeon settings through code in DunGen 2.10
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 UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using DunGen; | |
using System.Linq; | |
using DunGen.Graph; | |
public class BuildDungeonFlow : MonoBehaviour | |
{ | |
public List<GameObject> RoomPrefabs = new List<GameObject>(); | |
public List<GameObject> BossRoomPrefabs = new List<GameObject>(); | |
public List<GameObject> LockedDoorPrefabs = new List<GameObject>(); | |
private void Start() | |
{ | |
// Create the KeyManager | |
var keyManager = ScriptableObject.CreateInstance<KeyManager>(); | |
var blueKey = keyManager.CreateKey(); | |
blueKey.Colour = Color.blue; | |
var keySet = new KeyLockPlacement(); | |
keySet.ID = blueKey.ID; | |
keySet.Range = new IntRange(1, 1); | |
var lockSet = keySet; | |
// Create a pair of TileSets for later use | |
var startGoalTileSet = ScriptableObject.CreateInstance<TileSet>(); | |
startGoalTileSet.AddTile(RoomPrefabs.First(), 1, 1); // Just use the first room as our start & end tiles | |
var tileSetA = ScriptableObject.CreateInstance<TileSet>(); | |
tileSetA.AddTiles(RoomPrefabs.Take(3), 1, 1); // We're using the first 3 rooms in the RoomPrefabs list for this set.. | |
var tileSetB = ScriptableObject.CreateInstance<TileSet>(); | |
tileSetB.AddTiles(RoomPrefabs.Skip(3).Take(2), 1, 1); // ..and the last 2 for this one | |
var bossTileSet = ScriptableObject.CreateInstance<TileSet>(); | |
bossTileSet.AddTiles(BossRoomPrefabs, 1, 1); | |
// Tell the boss tile which locked door prefab(s) to use | |
var lockedDoorwayAssociation = new LockedDoorwayAssociation(); | |
lockedDoorwayAssociation.SocketGroup = DoorwaySocketType.Default; | |
foreach (var lockedDoor in LockedDoorPrefabs) | |
lockedDoorwayAssociation.LockPrefabs.Weights.Add(new GameObjectChance(lockedDoor, 1, 1, bossTileSet)); | |
bossTileSet.LockPrefabs.Add(lockedDoorwayAssociation); | |
// Create some Archetypes from the TileSets we just made | |
var archetypeA = ScriptableObject.CreateInstance<DungeonArchetype>(); | |
archetypeA.TileSets.Add(tileSetA); | |
archetypeA.BranchCount = new IntRange(0, 0); // No branching | |
var archetypeB = ScriptableObject.CreateInstance<DungeonArchetype>(); | |
archetypeB.TileSets.Add(tileSetB); | |
archetypeB.BranchCount = new IntRange(0, 0); | |
// Finally, build the dungeon flow itself.. | |
var flow = ScriptableObject.CreateInstance<DungeonFlow>(); | |
var builder = new DungeonFlowBuilder(flow) | |
.AddNode(startGoalTileSet, "Start") | |
.AddLine(archetypeA, 1f) | |
.AddNode(bossTileSet, "Mini-Boss") | |
.ContinueLine(1f) | |
.AddLine(archetypeB, 3f, keys: new KeyLockPlacement[] { keySet }) | |
.AddNode(bossTileSet, "Boss", true, false, locks: new KeyLockPlacement[] { lockSet }) | |
.AddNode(startGoalTileSet, "Goal"); | |
builder.Complete(); | |
// ..and pass it to a dungeon generator | |
var generator = new DungeonGenerator(); | |
generator.DungeonFlow = flow; | |
generator.Generate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment