コード例 #1
0
    /// <summary>
    /// マップを生成
    /// </summary>
    /// <param name="map">マップのデータ</param>
    public static void GenerateMap(int[,] map)
    {
        isGanerate = false;
        System.DateTime dt = System.DateTime.Now;

        int width  = map.GetLength(1);
        int height = map.GetLength(0);

        stageSize = new Vector2(width, height);

        generatedStage = new Piece[height, width];
        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                Vector2 position = new Vector2(j, i);

                //背景画像を設置
                SpriteRenderer back = new GameObject("[BackGroundChip]").AddComponent <SpriteRenderer>();
                back.transform.position = position;
                back.sprite             = ResourceLoader.GetChips(R_MapChipType.MainChip)[0];
                back.sortingOrder       = 0;

                int id = map[height - (i + 1), j];
                //Debug.Log(id);

                //idが14以外のときはピースを作成
                if (id != 14)
                {
                    CreatePiece(position, id);
                }
                else
                {
                    //それ以外はクリア場所を作成
                    Hole.CreateHole(position);
                }
            }
        }

        //画像ロード用
        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                Piece p = generatedStage[(height - (i + 1)), j];
                if (p)
                {
                    p.SpriteLoad();
                }
            }
        }

        System.TimeSpan ts = System.DateTime.Now - dt;
        Debug.Log("Map Generated. time: " + ts.Milliseconds + "ms");
        isGanerate = true;


        Vector2 center = new Vector2((width - 1f) * 0.5f, (height - 1f) * 0.5f);

        //背景画像を設置
        SpriteRenderer backGround = new GameObject("[BackGround]").AddComponent <SpriteRenderer>();

        backGround.sprite               = ResourceLoader.GetOtherSprite(R_OtherSpriteType.BackGround);
        backGround.color                = new Color(0.6f, 0.6f, 0.6f, 1);
        backGround.sortingOrder         = -1;
        backGround.transform.position   = center;
        backGround.transform.localScale = new Vector2(1, 1) * 2f;

        //環境エフェクト再生
        var ps = ParticleManager.Play(ParticleType.AmbientEffect, center, Quaternion.identity);
        var s  = ps.shape;

        s.scale = center * 3f;

        Vector3 cameraPos = center;

        cameraPos.x += 0.6f;
        cameraPos.z  = -1;

        //カメラ位置設定
        Camera.main.transform.position = cameraPos;
    }