예제 #1
0
        private void CreateCell(MapCoordinates coords, int index)
        {
            var position = new Vector3()
            {
                x = (coords.X + coords.Z * 0.5f - coords.Z / 2) * (HexCell.InnerRadius * 2f),//offsets every second row.
                y = 0f,
                z = coords.Z * (HexCell.OuterRadius * 1.5f)
            };

            HexCell cell = _cells[index] = Instantiate <HexCell>(CellPrefab);

            cell.transform.SetParent(_hexMesh.transform, false);
            cell.transform.localPosition = position;
            cell.Coordinates             = MapCoordinates.FromOffsetCoordinates(coords);
            cell.name  = $"Cell{cell.Coordinates}";
            cell.Color = DefaultColor;

            var label = Instantiate <Text>(CellLabelPrefab);

            label.rectTransform.SetParent(_canvas.transform, false);
            label.rectTransform.anchoredPosition = new Vector2(position.x, position.z);
            label.text = cell.Coordinates.ToFlatString();
        }