Exemplo n.º 1
0
    // 現在判定している通路に合うように回転させ,次に置くブロックを選択
    private void PutNextBlock(BitDirection dir, Vector2 position, int info)
    {
        int length = _mapGen.GetRoomInfos().Length;

        OneRoomInfo nextInfo = _mapGen.GetRoomInfos()[Random.Range(1, length)]; // プレハブリストからランダムに取得

        //通路データを取得
        _nextBlock = nextInfo;
        int nextCorridor = nextInfo.passagePos;

        // 3回転以内でつながる
        int i = 0;

        // TDOO: このループ気持ち悪いので今度直す
        while (i < 3)
        {
            // つながってなかったら
            if (((int)dir & nextCorridor) == 0
                // もしくは 右にも手前にも通路がなかったら回転する
                || ((nextCorridor & (int)BitDirection.RIGHT) == 0 && (nextCorridor & (int)BitDirection.FRONT) == 0))
            {
                // Bitデータを回転
                nextCorridor = RotateBitClockwise(nextCorridor);
                i++;
            }
            else
            {
                break;
            }
        }

        // オブジェクトの座標を計算
        Vector3 pos = new Vector3(position.x * _mapGen.ModelSize, 0, position.y * (-_mapGen.ModelSize));

        // オブジェクトの回転量を計算
        Quaternion rot = Quaternion.identity;

        rot = Quaternion.Euler(0.0f, 90.0f * i, 0.0f);

        // オブジェクトの生成
        var block = Instantiate(_nextBlock, pos, rot, gameObject.transform);

        // つくったオブジェクトを配列に格納
        block.passagePos = nextCorridor;
        _mapGen._maps[(int)position.x, (int)position.y] = block;
        _mapGen._rooms.Add(block);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 最初の部屋を生成する
    /// </summary>
    public void ChoiceFirstRoom()
    {
        //登録された部屋の種類を取得
        int count = _roomsInfos.Length;

        int firstRoom = 0;

        //部屋を生成する
        OneRoomInfo room = Instantiate(_roomsInfos[firstRoom], new Vector3(0, 0, 0), Quaternion.Euler(new Vector3(0, 180, 0)));

        room.transform.SetParent(transform);
        //地形がデータをマップに知らせる
        _maps[0, 0] = room;
        _rooms.Add(room);

        //部屋の通路の情報を取得
        return;
    }