Exemplo n.º 1
0
    void CreateCell(int x, int z, int i, Color color, int elevation)
    {
        Vector3 pos  = new Vector3((x + z * 0.5f - z / 2) * (HexMetrics.innerRadius * 2f), 0, z * (HexMetrics.outRadius * 1.5f));
        HexCell cell = cells[i] = Instantiate <HexCell>(cellPrefeb);

        cell.transform.localPosition = pos;
        cell.coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
        cell.Color = color;
        cell.x     = x;
        cell.z     = z;
        if (x > 0)
        {
            cell.SetNeightbor(HexDirection.W, cells[i - 1]);
        }
        if (z > 0)
        {
            if ((z & 1) == 0)
            {
                cell.SetNeightbor(HexDirection.SE, cells[i - cellCountX]);
                if (x > 0)
                {
                    cell.SetNeightbor(HexDirection.SW, cells[i - cellCountX - 1]);
                }
            }
            else
            {
                cell.SetNeightbor(HexDirection.SW, cells[i - cellCountX]);
                if (x < cellCountX - 1)
                {
                    cell.SetNeightbor(HexDirection.SE, cells[i - cellCountX + 1]);
                }
            }
        }
        //Text label = Instantiate<Text>(cellLabelPrefebs, gridCanvas.transform, false);
        //label.rectTransform.anchoredPosition = new Vector2(pos.x, pos.z);
        //label.text = cell.coordinates.ToStringOnSeparateLines();
        cell.Elevation = elevation;
        AddCellToChunk(x, z, cell);
        HexCellMsg tempMsg = new HexCellMsg();

        tempMsg.x         = x;
        tempMsg.y         = z;
        tempMsg.color     = color;
        tempMsg.Elevation = elevation;
    }
Exemplo n.º 2
0
    HexCellMsgArray CreateCellMsg()
    {
        HexCellMsgArray tempCell = new HexCellMsgArray()
        {
            cellArray = new List <HexCellMsg>()
        };

        for (int i = 0; i < cellCountX * cellCountZ; i++)
        {
            HexCellMsg temp = new HexCellMsg();
            temp.x         = cells[i].x;
            temp.y         = cells[i].z;
            temp.color     = cells[i].Color;
            temp.Elevation = cells[i].Elevation;
            tempCell.cellArray.Add(temp);
        }
        return(tempCell);
    }