Example #1
0
    /// <summary>
    /// 初始化格子
    /// </summary>
    /// <param name="boxCount"></param>
    void InitBox(int boxCount)
    {
        runtimeData.boxes = new List <GameBox>(boxCount);

        //设置Box
        for (int i = 0; i < boxCount; i++)
        {
            GameBox b = new GameBox();
            int     x = i % Width;
            int     y = i / Width;

            b.position = new Vector3(x * boxSize, 0, y * boxSize);

            //从下向上
            int downY = y * 2;
            int leftY = downY + 1;
            int upY   = downY + 2;

            //参考项目文件夹下的 棋盘格分配算法 文件
            int ed = downY * Width + y + x;
            int eu = upY * Width + y + x + 1;
            int el = leftY * Width + y + x;
            int er = el + 1;

            //设置边缘
            b.SetEdge(eu, EdgeType.Up);
            b.SetEdge(ed, EdgeType.Down);
            b.SetEdge(el, EdgeType.Left);
            b.SetEdge(er, EdgeType.Right);

            b.boxObject = Instantiate(boxObjectSrc);
            b.boxObject.Init();
            b.boxObject.SetColor(blankColor);
            b.boxObject.transform.position = b.position;

            runtimeData.boxes.Add(b);
        }
    }