예제 #1
0
            private void ConnectDoorsAt(Vector2Int position)
            {
                RoomConnectionBehaviour room = _grid[position];
                HashSet <Direction>     requiredDirections = FindRequiredDirectionsFor(position);

                foreach (DoorConnectionBehaviour door in room.Doors)
                {
                    if (requiredDirections.Contains(door.Direction))
                    {
                        Vector2Int neighbouringPosition          = position + door.Direction.ToVector2Int();
                        RoomConnectionBehaviour neighbouringRoom = _grid[neighbouringPosition];
                        DoorConnectionBehaviour neighbouringDoor = neighbouringRoom.GetDoorFacing(door.Direction.Opposite());
                        DoorConnectionBehaviour.Connect(door, neighbouringDoor);
                    }
                }
            }
        private static void ConnectDoors(Dictionary <Vector2Int, RoomConnectionBehaviour> roomGrid)
        {
            foreach (var pair in roomGrid)
            {
                Vector2Int position          = pair.Key;
                RoomConnectionBehaviour room = pair.Value;

                foreach (DoorConnectionBehaviour door in room.Doors)
                {
                    Vector2Int neighbouringPosition = position + door.Direction.ToVector2Int();

                    // expected to error if neighbouring room does not exist
                    RoomConnectionBehaviour neighbouringRoom = roomGrid[neighbouringPosition];
                    DoorConnectionBehaviour neighbouringDoor = neighbouringRoom.GetDoorFacing(door.Direction.Opposite());

                    // expected to error if neighbouring door does not exist
                    DoorConnectionBehaviour.Connect(door, neighbouringDoor);
                }
            }
        }