示例#1
0
 public bool IsTheSameAs(HexCoordinates other) => other.X == X && other.Y == Y && other.Z == Z;
示例#2
0
        private void CreateCell(int x, int z, int i)
        {
            var px       = (x + z / 2f - z / 2) * HexMetrics.InnerDiameter;
            var pz       = z * (1.5f * HexMetrics.OuterRadius);
            var position = new Vector3(px, 0f, pz);

            var cell = Instantiate <HexCell>(CellPrefab);

            cell.Index                   = i;
            cell.ColumnIndex             = x / HexMetrics.ChunkSizeX;
            cell.transform.localPosition = position;
            cell.Coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
            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;
            }

            cells[i] = cell;

            // connect neighbours, working backwards. e.g. connect the prior, and the bottom two corners if available
            // the setneighbour function does the reverse, so connecting back will conneck the prior cell to the current one too
            // in this way, all cells are connected to their neighbours

            if (x > 0)
            {
                cell.SetNeighbour(HexDirection.W, cells[i - 1]);
                if (wrapping && x == CellCountX - 1)
                {
                    cell.SetNeighbour(HexDirection.E, cells[i - x]);
                }
            }
            if (z > 0)
            {
                if ((z & 1) == 0) // non 'shunted' row, so always has bottom right, but first doesnt have bottom left
                {
                    cell.SetNeighbour(HexDirection.SE, cells[i - CellCountX]);
                    if (x > 0)
                    {
                        cell.SetNeighbour(HexDirection.SW, cells[i - CellCountX - 1]);
                    }
                    else if (wrapping)
                    {
                        cell.SetNeighbour(HexDirection.SW, cells[i - 1]);
                    }
                }
                else  // 'shunted' row, always has bottom left, but last does not have bottom right
                {
                    cell.SetNeighbour(HexDirection.SW, cells[i - CellCountX]);
                    if (x < CellCountX - 1)
                    {
                        cell.SetNeighbour(HexDirection.SE, cells[i - CellCountX + 1]);
                    }
                    else if (wrapping)
                    {
                        cell.SetNeighbour(HexDirection.SE, cells[i - CellCountX * 2 + 1]);
                    }
                }
            }

            var label = Instantiate <Text>(CellLabelPrefab);

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

            //cell.Elevation = 0;
            //cell.TerrainTypeIndex = 2; // mud
            //cell.WaterLevel = 1; // covered in water

            AddCellToChunk(x, z, cell);
        }