示例#1
0
    private void SetPuzzleTypeRoom(DungeonRoom _tmproom)
    {
        GeneratedTerrainData puzzleTerrain = loadData.terrainDataDic["Puzzle"][0];//Random.Range(0,loadData.terrainDataDic["Puzzle"].Count)-1];
        int sizex = puzzleTerrain.size.xMax;
        int sizey = puzzleTerrain.size.yMax;

        _tmproom.roomRect = new Rect(0, 0, sizex, sizey + 30);

        _tmproom.roomTileArray = new TileInfo[sizex, sizey + 30];
        for (int x = 0; x < sizex; x++)
        {
            for (int y = 0; y < sizey; y++)
            {
                if (puzzleTerrain.tileArray[x, y] != null)
                {
                    _tmproom.roomTileArray[x, y] = puzzleTerrain.tileArray[x, y];
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// NOTE : 미리 저장해둔 지형들을 사이즈를 검색하여 랜덤으로 선택하고 배치
    /// </summary>
    private void SetRandomTerrainRoom(DungeonRoom _tmproom)
    {
        //Terrain을 배치할때 각 Terrain마다 높이를 고려해야 하므로
        int possibleJumpHeightValue = 5;


        List <GeneratedTerrainData> possibleTerrain = new List <GeneratedTerrainData>();
        List <GeneratedTerrainData> terrainlist     = loadData.terrainDataDic["Terrain"];

        var remainXSize = _tmproom.roomRect.xMax - _tmproom.currentXPos;

        foreach (var tmpt in terrainlist)
        {
            //현재 남아있는 Xsize와 ysize를 방에 들어갈수있는지 체크하고 임시 생성한 리스트에 추가
            if (remainXSize > tmpt.size.xMax && (_tmproom.roomRect.yMax) > tmpt.size.yMax)
            {
                //Terrain을 처음 생성할 때
                if (_tmproom.beforeTerrainData == null)
                {
                    possibleTerrain.Add(tmpt);
                }
                else
                {
                    if (Mathf.Abs(_tmproom.beforeTerrainData.endHeight - tmpt.startHeight) <= possibleJumpHeightValue)
                    {
                        possibleTerrain.Add(tmpt);
                    }
                }
            }
        }

        //한개라도 가능한 지형이 있을경우 선택하여 타일 저장
        if (possibleTerrain.Count > 0)
        {
            GeneratedTerrainData selectedTerrain = possibleTerrain[Random.Range(0, possibleTerrain.Count - 1)];

            //Debug.Log("START : " + selectedTerrain.startHeight + ", END : " + selectedTerrain.endHeight);
            //현재 비어있는Room의 x값 초기화
            for (int i = 0; i < selectedTerrain.size.xMax; i++)
            {
                for (int j = 0; j < selectedTerrain.size.yMax; j++)
                {
                    if (_tmproom.roomTileArray[_tmproom.currentXPos + i, j] == null)
                    {
                        _tmproom.roomTileArray[_tmproom.currentXPos + i, j] = selectedTerrain.tileArray[i, j];
                    }
                }
            }

            _tmproom.beforeTerrainData = selectedTerrain;
            _tmproom.currentXPos       = _tmproom.currentXPos + selectedTerrain.size.xMax;


            SetRandomTerrainRoom(_tmproom);
        }
        //없을 경우 마지막으로 끝나는 지형의 나머지 값을 체크
        else
        {
            //음수처리 안해도될듯 하다
            int nextheight = Random.Range(_tmproom.beforeTerrainData.endHeight - possibleJumpHeightValue, _tmproom.beforeTerrainData.endHeight + possibleJumpHeightValue);

            for (int i = _tmproom.currentXPos; i < _tmproom.roomRect.xMax; i++)
            {
                for (int j = 0; j < nextheight; j++)
                {
                    _tmproom.roomTileArray[i, j] = new TileInfo(TileType.Terrain);
                }
            }
        }
    }