Beispiel #1
0
    void InitMap()
    {
        if (gridMap == null)
        {
            gridMap = new CGrid[Col, Row];
        }
        foreach (CGrid grid in gridMap)
        {
            if (grid)
            {
                GameObject.Destroy(grid.gameObject);
            }
        }

        RectTransform rectTransform = transform as RectTransform;

        for (int i = 0; i < Col; ++i)
        {
            for (int j = 0; j < Row; ++j)
            {
                CGrid grid = GameObject.Instantiate(gridBtn) as CGrid;
                grid.map = this;
                grid.setPos(i, j);
                grid.setParent(rectTransform);
                gridMap[i, j] = grid;
            }
        }

        for (int i = 0; i < Col; ++i)
        {
            for (int j = 0; j < Row; ++j)
            {
                if (Random.value < 0.1 && !(i == startCol && j == startRow))
                {
                    gridMap[i, j].select();
                }
            }
        }
    }