Hello, could you help me with this question. I need to know coordinates of the center of room and area around center to walls, area of whole room. Because I want to instantiate different objects around the room programmatycally and I don't want to instantiate it behind the room. I have tried to investigate different variants but I found only the center of room.
Viewing post in Edgar PRO - Unity Procedural Level Generator comments
Hey, I’m not sure what center of a room means here because rooms can have various shapes so it might be harder to compute the center. But what you can do is, for example, get all the floor tiles that are in the room and you can spawn something on them. If you wanted to do that, you’d have to create a post-processing task which gets an instance of the generated level. From there, you can get a list of all the rooms in the level (represented by the RoomInstanceGrid2D class). Inside that, you have the RoomTemplateInstance property which is a reference to the prefab from which the room was made. There you can find the Floor tilemap and get all the tiles inside it. You can use these floor tile positions as a base for your spawn behaviour.
Does that help?
Do you have any specific requirements for this? What’s your goal? One approach that is sometimes useful is to manually mark places where it’s valid to spawn something. You can use empty game objects to mark suitable places and then later pick some of these places and spawn some decorations/enemies there. That way, you have complete control over where things can spawn and you can also randomize. The downsize is that you have to mark these positions manually when creating room templates.