Edgar-Unity icon indicating copy to clipboard operation
Edgar-Unity copied to clipboard

Modifying the LevelGraph data at runtime

Open sjuzwicki opened this issue 2 years ago • 1 comments

Hi,

I would like to ask whether it is possible to manipulate the data for the level graph just before generating the dungeon.

My specific case: I want to be able to select a LevelGraph and a RoomTemplateSet via code just before generating a dungeon. The rationale is that the player will decide whether to generate a "long" or "short" dungeon (represented by different level graphs) and which biome (let's say "desert", "ice", "jungle", etc - represented by different room template sets).

I have been able to do both of the above by simply accessing the DungeonGenerator object and setting my desired values at runtime, but I ran into a problem with different biomes. All works perfectly well for normal rooms, but I have a spawn room in my level graphs which uses a room-specific template - so I need to set the template for that room as well, otherwise it will not match the biome.

I found that I would need to access the RoomBase children of the LevelGraph I am using (and I found which room to actually modify), but from what I can see that class only has getters and no visible way to actually set something. Would be grateful if you can correct me here :)

Of course what I can theoretically do is simply forget setting the biomes on the room template level and prepare separate level graphs for each biome. The issue is that then I would need a lot more level graphs (number of size options multiplied by number of biomes) so if possible I would prefer to avoid it.

sjuzwicki avatar Aug 03 '21 20:08 sjuzwicki

Hello, do you by any chance have the PRO version of the plugin? Because this whole scenario is quite simple there as you can implement custom input tasks. With them, you no longer have to prepare (assign) your room templates at design time. Instead, you can use the level graph only for the graph structure and then based on individual room types you implement a method that picks the correct room templates. So if you have a variable that indicates the current biome, you can just add an if statement that picks the correct spawn room for that biome.

If you don't have the PRO version, you can probably continue with what you're trying. If you found the correct RoomBase class, you should be able to just cast it to Room and access the room templates there. The RoomBase class is just the common ancestor for all the rooms (you can have custom room classes in the PRO version) and the concrete implementation in the free version is the Room class.

Let me know if this helps.

OndrejNepozitek avatar Aug 04 '21 05:08 OndrejNepozitek