Exemplo n.º 1
0
    void InitGridTiles(int width, int height)
    {
        int sortingCount = width * height;

        for (int y = 0; y < height; y++)
        {
            List <GameObject> tempList = new List <GameObject>();
            for (int x = 0; x < width; x++)
            {
                GameObject go = Instantiate(_gridPrefab);
                go.InitTransformAsChild(transform);
                go.name = "GridTile(" + x + ", " + y + ")";

                GridTile tile = go.GetComponent <GridTile>();
                Vector3  pos  = _grid.CellToWorld(new Vector3Int(x, y, 0));
                tile.transform.localPosition = pos;
                tile.MakeCollider(_gridSizeX, _gridSizeY);
                tile.MakeBoundaryLines(_gridSizeX, _gridSizeY);
                tile.SetSortingOrder(sortingCount--);

                tempList.Add(go);
            }
            _gridTiles.Add(tempList);
        }

        _width  = width;
        _height = height;
    }