public void Generate()
    {
        MapBlock mapBlock = Instantiate(m_BlockPrefab, transform).GetComponentInChildren <MapBlock>();

        mapBlock.StartingBlock = true;
        mapBlock.MainPathBlock = true;

        mapBlock.SpawnDirectionSign();

        mapBlock.FinishBlock = true;

        mapBlock.PopulateBlock();
    }
Пример #2
0
    private void GenerateRoomLayout()
    {
        m_Map = new MapBlock[m_Width, m_Height];
        m_PathRoomDescriptors = new List <BlockDescriptor>();

        // Spawn the rooms according to descriptors on the main path
        for (int i = 0; i < m_Path.Count; i++)
        {
            BlockDescriptor blockDescriptor = new BlockDescriptor();

            if (i > 0)
            {
                blockDescriptor.ConnectPathPositions(m_Path[i], m_Path[i - 1]);
            }

            if (i < m_Path.Count - 1)
            {
                blockDescriptor.ConnectPathPositions(m_Path[i], m_Path[i + 1]);
            }

            m_PathRoomDescriptors.Add(blockDescriptor);

            GameObject mapBlockPrefab = GetRandomMapBlockFromDescriptor(blockDescriptor);
            if (mapBlockPrefab == null)
            {
                continue;
            }

            MapBlock mapBlock = SpawnBlockAtPosition(mapBlockPrefab, m_Path[i].x, m_Path[i].y)
                                .GetComponentInChildren <MapBlock>();

            if (i == 0)
            {
                mapBlock.StartingBlock = true;
            }
            else if (i == m_Path.Count - 1)
            {
                mapBlock.GetComponentInChildren <MapBlock>().FinishBlock = true;
            }

            mapBlock.MainPathBlock = true;

            // Spawn direction signs and position to point at the next room
            mapBlock.SpawnDirectionSign();
            mapBlock.DirectionSign?.RotateTowards(m_Path[i + 1] - m_Path[i]);

            m_Map[m_Path[i].x, m_Path[i].y] = mapBlock;
        }

        // Fill in the non-crucial (outside of the main path) blocks
        for (int x = 0; x < m_Width; x++)
        {
            for (int y = 0; y < m_Height; y++)
            {
                if (m_Map[x, y] == null)
                {
                    m_Map[x, y] = SpawnBlockAtPosition(m_MapBlockPrefabs[Random.Range(0, m_MapBlockPrefabs.Count)], x,
                                                       y).GetComponentInChildren <MapBlock>();
                }

                m_Map[x, y].PopulateBlock();
            }
        }
    }