コード例 #1
0
    private IEnumerator GenerateMap()
    {
        //Add starting room's connection points
        AddConnectionPoints(startingRoom.GetComponentsInChildren <ConnectionPoint>());
        yield return(null);

        //While we haven't exceed the room limit,
        //let's try to generate the room for each connection point,
        //starting from the center
        while (ConnectionPoints.Count > 0 && roomPool.Count > 0)
        {
            ConnectionPoint currentPoint = ConnectionPoints.Dequeue();
            yield return(null);

            yield return(StartCoroutine(currentPoint.GenerateRoom(roomPool[0])));
        }

        isGeneratingRooms = false;
        yield return(new WaitForSeconds(0.03f));

        //Let us build the navmesh now for the AI
        isBuildingNavMesh = true;
        parent.GetComponent <NavMeshSurface>().BuildNavMesh();
        yield return(new WaitForSeconds(0.03f));

        //reactivate Deco
        foreach (GameObject room in generatedRooms)
        {
            room.transform.Find("Environment").Find("Deco").gameObject.SetActive(true);
        }
        isBuildingNavMesh = false;

        isGenerated = true;

        //For all the connection points left, let us generate the deadend
        //isGeneratingDeadends = true;
        foreach (ConnectionPoint currentPoint in ConnectionPoints)
        {
            yield return(null);

            yield return(StartCoroutine(currentPoint.GenerateRoom(deadend, true)));
        }
        //isGeneratingDeadends = false;
    }