示例#1
0
    void CreateCells(int x, int z, int i)
    {
        Vector3 position;

        position.x = (x + z * 0.5f - z / 2) * (2 * HexMetrics.InnerRadius);
        position.y = 0;
        position.z = z * (HexMetrics.OuterRadius * 1.5f);

        HexCell cell = cells[i] = Instantiate <HexCell>(cellPrefab);

        cell.transform.SetParent(transform, false);
        cell.transform.localPosition = position;
        cell.coordinate = HexCoordinate.FromOffsetCoordinate(x, z);
        cell.color      = defaultColor;

        if (x > 0)
        {
            cell.SetNeighbour(HexDirection.W, cells[i - 1]);
        }
        if (z > 0)
        {
            if ((z & 1) == 0)
            {
                cell.SetNeighbour(HexDirection.SE, cells[i - sizeX]);
                if (x > 0)
                {
                    cell.SetNeighbour(HexDirection.SW, cells[i - sizeX - 1]);
                }
            }
            else
            {
                cell.SetNeighbour(HexDirection.SW, cells[i - sizeX]);
                if (x < sizeX - 1)
                {
                    cell.SetNeighbour(HexDirection.SE, cells[i - sizeX + 1]);
                }
            }
        }

        Text text = Instantiate <Text>(cellLabelPrefab);

        text.rectTransform.SetParent(gridCanvas.transform, false);
        text.rectTransform.anchoredPosition = new Vector2(position.x, position.z);

        text.text = cell.coordinate.ToStringOnSeperateLines();

        cell.uiRect = text.rectTransform;
    }
示例#2
0
    private void CreateCell(HexCell cell, int x, int z)
    {
        int     ran = Random.Range(0, plainMat.Count);
        Vector3 position;

        position.x = (x + z * 0.5f - z / 2) * (HexMetrics.InnerRadius * 2);
        position.y = 0;
        position.z = z * (HexMetrics.OuterRadius * 1.5f);

        cell.InitHexCell();
        cell.GenerateMesh();
        cell.transform.SetParent(transform, false);
        cell.transform.localPosition = position;
        cell.SetMaterial(plainMat[ran]);
        //Debug.Log("cell created");
        cell.coordinate = HexCoordinate.FromOffsetCoordinate(x, z);
        cell.index      = x + z * mapWidth;
        hiddenCells.Add(cell);
    }