コード例 #1
0
    public void Activate()
    {
        // 一度すべてのマスを非アクティブ化
        Deactivate();

        // プレイヤーの現在位置を取得
        var pos = _player.transform.position;

        // プレイヤーの現在位置からどのマスにいるかを計算
        int px, py;

        px = (int)(pos.x + _rmg.ModelSize / 2) / _rmg.ModelSize;
        py = (int)(-pos.z + _rmg.ModelSize / 2) / _rmg.ModelSize;

        // 周囲1マスが配列の範囲内であればそのマスをアクティブ化

        // プレイヤーのマス
        int        width    = _rmg.GetSize().x;
        int        height   = _rmg.GetSize().y;
        Vector2Int gridPpos = new Vector2Int(px, py);

        // 自分のいるマスをアクティブ化
        var playerGrid = _rmg._maps[gridPpos.x, gridPpos.y];

        playerGrid.gameObject.SetActive(true);
        _rmg._maps[gridPpos.x, gridPpos.y].UpdateActived(true);
        Debug.Log(_rmg._maps[gridPpos.x, gridPpos.y].gameObject.name);


        // 調べる方向
        Vector2 vec = new Vector2(0, 1);
        // 調べるマス
        Vector2Int gridSpos = Vector2Int.zero;

        // 周囲4マスを調べる
        for (int i = 0; i < 4; i++)
        {
            gridSpos.x = (int)Mathf.Round(gridPpos.x + vec.x);
            gridSpos.y = (int)Mathf.Round(gridPpos.y + vec.y);

            gridSpos.x = Mathf.Clamp(gridSpos.x, 0, width - 1);
            gridSpos.y = Mathf.Clamp(gridSpos.y, 0, height - 1);

            var searchGrid = _rmg._maps[gridSpos.x, gridSpos.y];
            if (searchGrid != null)
            {
                searchGrid.gameObject.SetActive(true);
            }

            vec   = Quaternion.Euler(0, 0, 90) * vec;
            vec.x = Mathf.Round(vec.x);
            vec.y = Mathf.Round(vec.y);
        }
    }
コード例 #2
0
    /// <summary>
    /// 最初に作られた部屋の取得
    /// </summary>
    /// <returns>幅と奥行きのvector2(int)</returns>
    public Vector2Int GetFirstRoom()
    {
        for (int z = 0; z < _mapGen.GetSize().y; z++)
        {
            for (int x = 0; x < _mapGen.GetSize().x; x++)
            {
                if (_mapGen._maps[x, z] != null)
                {
                    return(new Vector2Int(x, z));
                }
            }
        }

        //部屋が無い場合
        Debug.Log("Not room");
        return(new Vector2Int(0, 0));
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        //最初の部屋を生成する
        _mapGen.ChoiceFirstRoom();

        // 部屋の幅、奥行きを取得
        _mapSize = _mapGen.GetSize();

        // マップの生成を実行
        GenerateMap(_mapGen._maps, _mapSize.y, _mapSize.x);
    }
コード例 #4
0
    // Use this for initialization

    private void Awake()
    {
        // 大きさを指定してマップを生成する
        if (Difficulty.Instance._difficulty == "NORMAL")
        {
            _mapGen.MapResize(3, 3);
        }
        else if (Difficulty.Instance._difficulty == "HARD")
        {
            _mapGen.MapResize(6, 6);
        }

        //最初の部屋を生成する
        _mapGen.ChoiceFirstRoom();

        _mapSize = _mapGen.GetSize();

        // マップの生成を実行
        GenerateMap(_mapGen._maps, _mapSize.y, _mapSize.x);
    }