Пример #1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var coordinates = new HexagonCoordinates(property.FindPropertyRelative("x").intValue,
                                                 property.FindPropertyRelative("z").intValue);

        position = EditorGUI.PrefixLabel(position, label);
        GUI.Label(position, coordinates.ToString());
    }
Пример #2
0
    public Cell GetCell(Vector3 position)
    {
        position = transform.InverseTransformPoint(position);
        var coordinates = HexagonCoordinates.FromPosition(position);
        var index       = coordinates.x + coordinates.z * _cellCountX + coordinates.z / 2;

        return(_cells[index]);
    }
Пример #3
0
    void CreateCell(int x, int z, int i)
    {
        Vector3 position;

        if (z % 2 == 0)
        {
            position.x = x * (2f * Metrics.InnerRadius);
        }
        else
        {
            position.x = (x + 0.5f) * (2f * Metrics.InnerRadius);
        }
        position.y = 0f;
        position.z = z * (1.5f * Metrics.OuterRadius);

        _cells[i] = Instantiate(cellPrefab);
        _cells[i].transform.localPosition = position;
        _cells[i].coordinates             = HexagonCoordinates.FromOffsetCoordinates(x, z);

        _cells[i].Color = _defaultColor;
        //Connecting Neighbours
        if (x > 0)
        {
            _cells[i].SetNeighbour(Direction.West, _cells[i - 1]);
        }

        if (z > 0)
        {
            if (z % 2 == 0)
            {
                _cells[i].SetNeighbour(Direction.SouthEast, _cells[i - _cellCountX]);
                if (x > 0)
                {
                    _cells[i].SetNeighbour(Direction.SouthWest, _cells[i - _cellCountX - 1]);
                }
            }
            else
            {
                _cells[i].SetNeighbour(Direction.SouthWest, _cells[i - _cellCountX]);
                if (x < _cellCountX - 1)
                {
                    _cells[i].SetNeighbour(Direction.SouthEast, _cells[i - _cellCountX + 1]);
                }
            }
        }

        var coords = Instantiate(coordsTextPrefab);

        coords.rectTransform.anchoredPosition = new Vector2(position.x, position.z);
        coords.text           = _cells[i].coordinates.ToStringOnSeparateLines();
        _cells[i].labelHolder = coords.rectTransform;
        _cells[i].Elevation   = 0;

        AddCellToChunk(x, z, _cells[i]);
    }
Пример #4
0
    public Cell GetCell(HexagonCoordinates coordinates)
    {
        var z = coordinates.z;

        if (z < 0 || z >= _cellCountZ)
        {
            return(null);
        }
        var x = coordinates.x + z / 2;

        if (x < 0 || x >= _cellCountX)
        {
            return(null);
        }
        return(_cells[x + z * _cellCountX]);
    }
    private void MakeCoordinates(HexagonTille centerTile)
    {
        Vector3 centerPosition = centerTile.transform.position;


        int neighbourCount = centerTile.NeighbourList.Count;

        for (int i = 0; i < neighbourCount; i++)
        {
            var neighbour = centerTile.NeighbourList[i];
            if (neighbour.HexagonCoordinates.HasCoordinates)
            {
                continue;
            }

            Vector3 neighbourPosition = neighbour.transform.position;
            Size    ySize             = Size.Equal;
            if (neighbourPosition.y > centerPosition.y)
            {
                ySize = Size.Bigger;
            }
            else if (neighbourPosition.y < centerPosition.y)
            {
                ySize = Size.Smaller;
            }

            Size xSize = Size.Smaller;
            if (neighbourPosition.x > centerPosition.x)
            {
                xSize = Size.Bigger;
            }

            int tileX = centerTile.HexagonCoordinates.X;
            int tileZ = centerTile.HexagonCoordinates.Z;
            HexagonCoordinates coordinates;

            if (xSize == Size.Bigger)
            {
                if (ySize == Size.Equal)
                {
                    coordinates = new HexagonCoordinates(tileX + 1, tileZ);
                }
                else if (ySize == Size.Bigger)
                {
                    coordinates = new HexagonCoordinates(tileX, tileZ + 1);
                }
                else
                {
                    coordinates = new HexagonCoordinates(tileX + 1, tileZ - 1);
                }
            }
            else
            {
                if (ySize == Size.Equal)
                {
                    coordinates = new HexagonCoordinates(tileX - 1, tileZ);
                }
                else if (ySize == Size.Bigger)
                {
                    coordinates = new HexagonCoordinates(tileX - 1, tileZ + 1);
                }
                else
                {
                    coordinates = new HexagonCoordinates(tileX, tileZ - 1);
                }
            }

            coordinates.HasCoordinates   = true;
            neighbour.HexagonCoordinates = coordinates;
        }
    }