void createRoom(float posx, float posy, float posz, int mapx, int mapy, int mapz) { cubePlacement cube = roomCube(mapx, mapy, mapz); GameObject room = Instantiate(DungeonRoomsType[8]); room.transform.position = new Vector3(posx, posy, posz); //room.transform.eulerAngles = cube.rotation; room.transform.localScale = new Vector3(RoomSize, RoomSize, RoomSize); }
cubePlacement roomCube(int x, int y, int z) { int openings = 0; cubePlacement result = new cubePlacement(); bool[] sides = Enumerable.Repeat(false, 6).ToArray();; try { if (DungeonMap[x + 1][y][z] == true) //front { sides[0] = true; openings++; } } catch { } try { if (DungeonMap[x - 1][y][z] == true) //back { sides[1] = true; openings++; } } catch { } try { if (DungeonMap[x][y + 1][z] == true) //left { sides[2] = true; openings++; } } catch { } try { if (DungeonMap[x][y - 1][z] == true) //right { sides[3] = true; openings++; } } catch { } try { if (DungeonMap[x][y][z + 1] == true) //up { sides[4] = true; openings++; } } catch { } try { if (DungeonMap[x][y][z - 1] == true) //down { sides[5] = true; openings++; } } catch { } //check switch (openings) { case 1: result.cube = DungeonRoomsType[0]; break; case 2: if (sides[0] == sides[1] && sides[2] == sides[3] && sides[4] == sides[5]) { result.cube = DungeonRoomsType[2]; } else { result.cube = DungeonRoomsType[1]; } break; case 3: if (sides[0] != sides[1] && sides[2] != sides[3] && sides[4] != sides[5]) { result.cube = DungeonRoomsType[3]; } else { result.cube = DungeonRoomsType[4]; } break; case 4: if (sides[0] == sides[1] && sides[2] == sides[3] && sides[4] == sides[5]) { result.cube = DungeonRoomsType[5]; } else { result.cube = DungeonRoomsType[6]; } break; case 5: result.cube = DungeonRoomsType[7]; break; default: result.cube = DungeonRoomsType[8]; break; } result.rotation = getCubeRotation(sides, openings); return(result); }