Exemple #1
0
        private void CreateCell(int x, int z, int i)
        {
            Vector3 position;

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

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

            cell.transform.localPosition = position;
            cell.coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
            cell.Index       = i;
            cell.ColumnIndex = x / HexMetrics.chunkSizeX;
            cell.ShaderData  = cellShaderData;
            if (wrapping)
            {
                cell.Explorable = z > 0 && z < cellCountZ - 1;
            }
            else
            {
                cell.Explorable =
                    x > 0 && z > 0 && x < cellCountX - 1 && z < cellCountZ - 1;
            }

            // link neighbor
            if (x > 0)
            {
                cell.SetNeighbor(HexDirection.W, cells[i - 1]);
                if (wrapping && x == cellCountX - 1)
                {
                    cell.SetNeighbor(HexDirection.E, cells[i - x]);
                }
            }
            if (z > 0)
            {
                if ((z & 1) == 0)
                {
                    cell.SetNeighbor(HexDirection.SE, cells[i - cellCountX]);
                    if (x > 0)
                    {
                        cell.SetNeighbor(HexDirection.SW, cells[i - cellCountX - 1]);
                    }
                    else if (wrapping)
                    {
                        cell.SetNeighbor(HexDirection.SW, cells[i - 1]);
                    }
                }
                else
                {
                    cell.SetNeighbor(HexDirection.SW, cells[i - cellCountX]);
                    if (x < cellCountX - 1)
                    {
                        cell.SetNeighbor(HexDirection.SE, cells[i - cellCountX + 1]);
                    }
                    else if (wrapping)
                    {
                        cell.SetNeighbor(
                            HexDirection.SE, cells[i - cellCountX * 2 + 1]
                            );
                    }
                }
            }

            Text label = Instantiate(cellLabelPrefab);

            label.rectTransform.anchoredPosition =
                new Vector2(position.x, position.z);
            cell.uiRect = label.rectTransform;

            cell.Elevation = 0;

            AddCellToChunk(x, z, cell);
        }