예제 #1
0
    private void InitField(Vector2Int size)
    {
        cells = new Cell[size.x, size.y];

        var cellSize       = Vector2Extensions.Multiply(CellPrefab.GetComponent <RectTransform>().sizeDelta, CellPrefab.GetComponent <RectTransform>().localScale);
        var wholeFieldSize = new Vector2(cellSize.x * Options.FieldSize.x, cellSize.y * Options.FieldSize.y);
        var shift          = new Vector3(-wholeFieldSize.x, -wholeFieldSize.y) / 2;

        for (int i = 0; i < size.x; ++i)
        {
            for (int j = 0; j < size.y; ++j)
            {
                var c = new Vector2Int(i, j);

                var cellObj = Object.Instantiate(CellPrefab, Field.transform);
                cellObj.transform.localPosition = shift + new Vector3(i * cellSize.x, j * cellSize.y);

                var cell = cellObj.GetComponent <Cell>();
                cells[i, j] = cell;

                cell.Init(new CellData(false, false, false));
                cell.LeftClick  += () => CellLeftClick(c);
                cell.RightClick += () => CellRightClick(c);
                cell.Opened     += OnCellOpened;
            }
        }
    }