Esempio n. 1
0
    public void CreateCell(int x, int y)
    {
        Vector3 cellPos = new Vector3(x * (HexMetrics.innerRadius + cellPadding) * 2f, y * (HexMetrics.outerRadius + cellPadding) * 1.5f, 0);

        cellPos.x += (HexMetrics.innerRadius + cellPadding) * (y % 2);


        HexCell cell = hexCells[x, y] = Instantiate(cellPrefab).GetComponent <HexCell>();

        cell.runeGrid        = runeGrid;
        cell.axialCordinates = HexMetrics.FromOffsetToAxialCoords(x, y);
        cell.runeID          = 0;

        cell.cellNeighbours = new HexCell[6];

        if (x > 0)
        {
            cell.SetNeighbour(HexDirection.W, hexCells[x - 1, y]);
        }
        if (y > 0)
        {
            if (y % 2 == 1)
            {
                cell.SetNeighbour(HexDirection.SW, hexCells[x, y - 1]);
                if (x + 1 < width)
                {
                    cell.SetNeighbour(HexDirection.SE, hexCells[x + 1, y - 1]);
                }
            }
            else
            {
                if (x > 0)
                {
                    cell.SetNeighbour(HexDirection.SW, hexCells[x - 1, y - 1]);
                }
                cell.SetNeighbour(HexDirection.SE, hexCells[x, y - 1]);
            }
        }


        cell.transform.SetParent(this.transform, false);
        cell.transform.localPosition = cellPos;
        cell.transform.localScale    = Vector3.one * HexMetrics.outerRadius * 2;
    }