Hello
So I am trying to implement a setup method that needs to do a bunch of checks, and based on these checks implement a prefab.
So heres the idea of what i am doing:
Imagine a sky scraper of which has rooms on every floor. Now this sky scraper has a room which is an elevator room type.
So imagine a layout like this:
In this above example the two elevators are considered “connected” because they are one Y position apart and on the same X axis.
Because of this, i can now implement an elevator platform and set its linked rooms to those two elevators  not terribly challenging to do that.
How ever it gets a lot more complicated when i need to link up multiple elevators for example:
So i kinda started to work out a way to connect it all like this:
void SetElevators(){
List<Room> elevators = new List<Room>();
for(int i = 0; i < rooms.Count; i++){
if(rooms[i].roomType == RoomType.Elevator){
// get neighbours
elevators.Clear();
elevators.Add(rooms[i]); // ADD the first elevator
for(int j = 0; j < rooms.Count; j++){
// if not same room type or not on same xaxis, or it is the same room = skip it
if(rooms[j].roomType != rooms[i].roomType  rooms[j].x != rooms[i].x  rooms[i] == rooms[j]){ continue; }
elevators.Add(rooms[j]); //ADD the next elevator
}
//instantiate prefab connected to just these elevators
CreateElevatorPlatform(elevators);
}
}
}
The problem here is two things:

Duplication, this design is surely going to just create a lot of duplication for every elevator that exists. For example, from Elevator A i get neighbor Elevator B, then on B i am getting elevator neighbor A, which i already have connected up when i was getting neighbors for elevator A. So i end up with TWO elevator platforms for the same connection this cause a collision in the same elevator shaft.

Say you have two elevators separated by a normal room:
These elevators are not connected obviously, but from my current code logic, it will create a connection because i didn’t check if they are directly neighbors. But i also can’t just check for just y+1 or y1, because there could be elevators connected through multiple floors. As in first example there is 3 floors of elevators all connected one after another.
So i am completely lost on how to implement this logic.
Hope some one can help shed light on what is the best solution here.
Thanks.