コード例 #1
0
        public HexCell GetCell(Vector3 position)
        {
            position = transform.InverseTransformPoint(position);
            var coordinates = HexCoordinate.CreateFromPosition(position);
            var index       = coordinates.X + coordinates.Z * ChunkCountX * HexMetrics.chunkSizeX + coordinates.Z / 2;

            return(_cells[index]);
        }
コード例 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var coordinates = new HexCoordinate(
                property.FindPropertyRelative("x").intValue,
                property.FindPropertyRelative("z").intValue
                );

            GUI.Label(position, coordinates.ToString());
        }
コード例 #3
0
        private void CreateCell(int x, int z, int i)
        {
            Vector3 pos;

            pos.x = (x * 2 + z % 2) * HexMetrics.innerRadius;
            pos.y = 0;
            pos.z = z * 1.5f * HexMetrics.outerRadius;
            var cell = _cells[i] = Instantiate <HexCell>(HexCellPrefab);

            cell.transform.localPosition = pos;
            cell.HexCoordinate           = HexCoordinate.CreateFromOffset(x, z);
            cell.TerrainTypeIndex        = this.DefaultColorIndex;
            if (x > 0)
            {
                cell.SetNeighbor(HexDirection.W, _cells[i - 1]);
            }

            var width = ChunkCountX * HexMetrics.chunkSizeX;

            if (z > 0)
            {
                if ((z & 1) == 0)
                {
                    cell.SetNeighbor(HexDirection.SE, _cells[i - width]);
                    if (x > 0)
                    {
                        cell.SetNeighbor(HexDirection.SW, _cells[i - width - 1]);
                    }
                }
                else
                {
                    cell.SetNeighbor(HexDirection.SW, _cells[i - width]);
                    if (x < width - 1)
                    {
                        cell.SetNeighbor(HexDirection.SE, _cells[i - width + 1]);
                    }
                }
            }

            var label = Instantiate(HexLabelPrefab);

            label.rectTransform.anchoredPosition = new Vector2(pos.x, pos.z);
            label.text = cell.HexCoordinate.ToSplitString();

            cell.uiRect     = label.rectTransform;
            cell.Evaluation = 0;

            AddCellToChunk(x, z, cell);
        }
コード例 #4
0
ファイル: HexCoordinate.cs プロジェクト: zcbnu/hexmap
 public int DistanceTo(HexCoordinate coordinate)
 {
     return(((x < coordinate.x ? coordinate.x - this.x : this.x - coordinate.x)
             + (Y < coordinate.Y ? coordinate.Y - this.Y : this.Y - coordinate.Y)
             + (Z < coordinate.z ? coordinate.z - this.z : this.z - coordinate.z)) / 2);
 }