I tried using
DunGen and 2D Toolkit during Global Game Jam 2017 last weekend and totally failed. I was setting up the TileMap prefabs correctly per instructions I've found here, but whenever I generated the map, it came out a total mess with nothing rendered correctly at all, tiles overlapping, render data all out of whack, etc. Being a game jam, I didn't have time to sort it out, but tonight I finally dug in and got it working. It seems to be a problem using TileMap prefabs and placing them at new locations during runtime. To get it working, I had to tell each TileMap to
.ForceBuild() after the whole map was done being generated. Here's the script I wrote that I attached to the runtime map generator:
using UnityEngine;
using DunGen;
public class TileMapPrefabFix : MonoBehaviour {
void OnEnable() {
GetComponent<RuntimeDungeon>().Generator.OnGenerationStatusChanged += Generator_OnGenerationStatusChanged;
}
void OnDisable() {
GetComponent<RuntimeDungeon>().Generator.OnGenerationStatusChanged -= Generator_OnGenerationStatusChanged;
}
private void Generator_OnGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status) {
if (status == GenerationStatus.Complete) {
tk2dTileMap[] tileMaps = generator.Root.GetComponentsInChildren<tk2dTileMap>();
foreach (tk2dTileMap tileMap in tileMaps) {
tileMap.ForceBuild();
}
}
}
}