-
-
Save AG-Dan/04e0d85ae651dc15b7e24b6ec416cc09 to your computer and use it in GitHub Desktop.
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 System.Collections.Generic; | |
using UnityEngine; | |
/// <summary> | |
/// Injects multiple tiles from a TileSet (between MinCount - MaxCount) | |
/// Tiles can appear anywhere throughout the dungeon | |
/// </summary> | |
public class InjectTileRange : MonoBehaviour | |
{ | |
public TileSet TileSet = null; | |
public int MinCount = 1; | |
public int MaxCount = 3; | |
private void Start() | |
{ | |
var runtimeDungeon = FindObjectOfType<RuntimeDungeon>(); | |
var generator = runtimeDungeon.Generator; | |
generator.TileInjectionMethods += InjectTiles; | |
} | |
private void InjectTiles(System.Random randomStream, ref List<InjectedTile> tilesToInject) | |
{ | |
// Required tiles | |
for (int i = 0; i < MinCount; i++) | |
InjectSingleTile(randomStream, ref tilesToInject, true); | |
// Optional tiles | |
int optionalTileCount = MaxCount - MinCount; | |
for (int i = 0; i < optionalTileCount; i++) | |
InjectSingleTile(randomStream, ref tilesToInject, false); | |
} | |
private void InjectSingleTile(System.Random randomStream, ref List<InjectedTile> tilesToInject, bool isRequired) | |
{ | |
// Just allow the tile to appear anywhere in the dungeon | |
bool isOnMainPath = randomStream.NextDouble() < 0.5; // Equal chance to appear on main or branch path | |
float pathDepth = (float)randomStream.NextDouble(); // 0-1 | |
float branchDepth = (float)randomStream.NextDouble(); // 0-1 | |
var tile = new InjectedTile(TileSet, isOnMainPath, pathDepth, branchDepth, isRequired); | |
tilesToInject.Add(tile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment