Пример #1
0
 //Procedurally spawns obstacles at the node positions
 private void SpawnObstacles()
 {
     for (int i = 0; i < nodes.Length; i++)
     {
         if (nodes[i].x != xCentre - 0.5f || nodes[i].z != zCentre - 0.5f)
         {
             float obstacleChance = Random.Range(0f, 1f);
             if (obstacleChance < roomTypeController.getPillarChance())
             {
                 SpawnPillar(nodes[i].x, nodes[i].z, roomTypeController.getWalls());
                 SpawnDecorations(nodes[i].x, nodes[i].z - 1f);
             }
             else if (obstacleChance < roomTypeController.getObstructionChance())
             {
                 float        obstructionToSpawn = Random.Range(0f, 1f);
                 float[]      chances            = roomTypeController.getObstructionChances();
                 GameObject[] obstructions       = roomTypeController.getObstructions();
                 for (int j = 0; j < obstructions.Length; j++)
                 {
                     if (obstructionToSpawn <= chances[j])
                     {
                         Instantiate(obstructions[j], new Vector3(nodes[i].x, 0f, nodes[i].z + 0.5f), Quaternion.identity, transform);
                         j = obstructions.Length;
                     }
                 }
             }
         }
     }
 }
Пример #2
0
    [SerializeField] private GameObject item;                                    //empty loot gameObject that will be populated from the loot pools

    //spawns the physical room
    public void SpawnRoom()
    {
        //spawning invisible plane, used to create a navmesh to help control enemy AI
        GameObject floor = Instantiate(floorPlane, new Vector3(xCentre - 0.5f, -0.01f, zCentre - 0.5f), Quaternion.identity, gameObject.transform);

        floor.transform.localScale = new Vector3((float)width / 10f, 0f, (float)height / 10f);

        //set collider bounds
        roomBounds      = gameObject.GetComponent <BoxCollider>();
        roomBounds.size = new Vector3(width - 1f, 2f, height - 1f);

        //sets up the roomTypeController
        switch (roomType)
        {
        case 0: roomTypeController = gameObject.AddComponent <SpawnRoomController>();
            GameObject.Find("Player").transform.position         = new Vector3(xCentre, transform.position.y, zCentre);
            GameObject.Find("CameraPosition").transform.position = new Vector3(xCentre, 10f, zCentre - 10f);
            break;

        case 1: roomTypeController = gameObject.AddComponent <BossRoomController>(); break;

        case 2: roomTypeController = gameObject.AddComponent <ShopRoomController>(); break;

        case 3: roomTypeController = gameObject.AddComponent <LibraryRoomController>(); break;

        case 4: roomTypeController = gameObject.AddComponent <ShrineRoomController>(); break;

        case 5: roomTypeController = gameObject.AddComponent <MobRoomController>(); break;

        case 6: roomTypeController = gameObject.AddComponent <LootRoomController>(); break;

        case 7: roomTypeController = gameObject.AddComponent <GenericRoomController>(); break;
        }

        //Generating floors and walls
        SpawnWalls(roomTypeController.getWalls());
        tileGenerator.DrawRoom(xCentre, zCentre, width, height, roomTypeController.getTiles());
        tileGenerator.DrawFog(xCentre, zCentre, width, height); //Darkening rooms until they're explored
        roomTypeController.SpawnRoom(xCentre, zCentre, width, height);
        SpawnTileDecorations();

        //setting up the rooms minimap components
        GameObject MMFloor = Instantiate(roomTypeController.getMinimapFloor(), new Vector3(xCentre, 99.5f, zCentre), Quaternion.identity, gameObject.transform);

        MMFloor.transform.localScale = new Vector3(MMFloor.transform.localScale.x * width, MMFloor.transform.localScale.y, MMFloor.transform.localScale.z * height);
        minimapComponents.Add(MMFloor);
        MMFloor.SetActive(false);

        //Generating obstacles (pillars, tables etc)
        CreateNodes();
        SpawnObstacles();
    }