I’m trying to make a rogue-like game with premade room patterns which should be chosen randomly (like Binding of Isaac or Enter the Gungeon). At first I wanted to make integers arrays to represent the different patterns and stock them in another array. The problem of this method is that I should define the array which stock the other and then define all his index by hand. It is not very efficient if there are many patterns… I don’t find any other way to do that, so how could I do ?
You can make each room pattern a prefab, and then store the list of all patterns in an array inside a manager object. Something along these lines:
// Attached to all of your room patterns. Contains helpful information and methods.
public class RoomPattern : MonoBehaviour
{
}
// This contains an array of all room patterns and also generates levels by
// piecing patterns together.
public class LevelGenerator : MonoBehaviour
{
[SerializeField] private RoomPattern[] roomPatterns;
}
You can add a LevelGenerator object to your scene, and then drag the RoomPattern prefabs into its array.
Thank you for your answer. I didn’t want to use this method before as it would have had a big memory cost with the method I used, but with the one I use now this cost is reduced so it’s fine.