コード例 #1
0
ファイル: RoomManager.cs プロジェクト: Staszk/Escape-Artist
    private void SpawnRooms(GridSpace[,] gridSpaces, int col, int row)
    {
        spawnedSecureRooms = new List <SecureRoom>();

        for (int i = 0; i < col; ++i)
        {
            for (int j = 0; j < row; j++)
            {
                GameObject room = null;
                Vector3    pos  = new Vector3(28 * i - (2 * 28), 0, 28 * j - (2 * 28));
                int        randomIndex;

                GridSpace thisSpot = gridSpaces[i, j];

                if (thisSpot == GridSpace.objective)
                {
                    room = Instantiate(objectiveRoom, pos, Quaternion.identity);
                }
                else if (thisSpot == GridSpace.secure)
                {
                    //Grabs Random Room from the List based on index
                    randomIndex = Random.Range(0, possibleSecureRooms.Count);

                    room = Instantiate(possibleSecureRooms[randomIndex], pos, Quaternion.identity);
                }
                else if (thisSpot == GridSpace.civilian)
                {
                    //Grabs Random Room from the List based on index
                    randomIndex = Random.Range(0, possibleCivilianRooms.Count);

                    room = Instantiate(possibleCivilianRooms[randomIndex], pos, Quaternion.identity);
                }
                else if (thisSpot == GridSpace.gala)
                {
                    //Grabs Random Room from the List based on index
                    randomIndex = Random.Range(1, possibleGalaRooms.Count);

                    if (startingRoom == null)
                    {
                        room         = Instantiate(possibleGalaRooms[0], pos, Quaternion.identity);
                        startingRoom = room.GetComponent <Room>();
                        currentRoom  = startingRoom;
                    }
                    else
                    {
                        room = Instantiate(possibleGalaRooms[randomIndex], pos, Quaternion.identity);
                    }
                }
                else if (thisSpot == GridSpace.edge)
                {
                    room = Instantiate(edgeRoom, pos, Quaternion.identity);

                    room.GetComponent <EdgeRoom>().Create(CreateEdge(gridSpaces, i, j), wallTypes);

                    room.transform.SetParent(transform);

                    continue;
                }

                if (room != null)
                {
                    room.transform.SetParent(transform);
                    roomLayout[i, j] = room.GetComponent <Room>();

                    if (thisSpot == GridSpace.secure || thisSpot == GridSpace.objective)
                    {
                        SecureRoom scr = room.GetComponent <SecureRoom>();

                        spawnedSecureRooms.Add(scr);

                        scr.GiveQuad(alertQuad);
                    }

                    string alphanumeric = alphabet.Substring(i, 1) + (roomLayout.GetLength(1) - j).ToString();

                    bool[] doors = CheckWalls(gridSpaces, i, j);

                    roomLayout[i, j].Setup(i, j, alphanumeric, Room.GetRoomTypeFromGridSpace(thisSpot), doors, wallTypes);
                    roomLayout[i, j].GiveMaterial(hiddenMat);

                    if (thisSpot != GridSpace.edge)
                    {
                        navMeshBaker.AddSurface(room.GetComponent <NavMeshSurface>());
                    }
                }
            }
        }
    }