Exemple #1
0
 /// <summary>
 /// Return data about the tile at the specified position.
 /// </summary>
 public bool TryGetTile(HexCoords tileCoords, out HexTileData data)
 {
     data = FindTileForCoords(tileCoords);
     return(data != null);
 }
Exemple #2
0
 /// <summary>
 /// Returns the chunk for the tile at the specified coordinates, or
 /// null if none exists.
 /// </summary>
 public HexChunk FindChunkForCoordinates(HexCoords coordinates)
 {
     return(Chunks.Where(c => c.Tiles.Where(tile => tile.Coordinates == coordinates).Any())
            .FirstOrDefault());
 }
Exemple #3
0
 /// <summary>
 /// Returns whether or not the specified tile exists.
 /// </summary>
 public bool ContainsTile(HexCoords tileCoords)
 {
     return(FindTileForCoords(tileCoords) != null);
 }
Exemple #4
0
 /// <summary>
 /// Returns the tile at the specified coordinates, or null
 /// if none exists.
 /// </summary>
 private HexTileData FindTileForCoords(HexCoords coords)
 {
     return(Tiles
            .Where(t => t.Position.Coordinates == coords)
            .FirstOrDefault());
 }
Exemple #5
0
        /// <summary>
        /// Generate the top for the hex tile, assiging its vertices, triangles and UVs to the supplied lists.
        /// </summary>
        private static void GenerateTop(HexCoords position, List <Vector3> vertices, List <int> triangles, List <Vector2> uv, float diameter)
        {
            var uvBasePos = HexCoordsToUV(position);

            vertices.AddRange(HexMetrics.GetHexVertices(diameter));

            // Each third tile needs a UV seam through the middle of it for textures to loop properly.
            var offsetCoords = position.ToOffset();

            if (offsetCoords.x % 2 == 0 && offsetCoords.y % 3 == 0)
            {
                vertices.Insert(4, vertices[0]);
                vertices.Insert(5, vertices[3]);

                triangles.AddRange(new int[]
                {
                    // Start with the preset triangles for the hex top.
                    0, 1, 2,
                    0, 2, 3,
                    4, 5, 7,
                    7, 5, 6
                });

                for (var i = 0; i < vertices.Count; i++)
                {
                    float uvY;
                    if (i == 0 || i == 3)
                    {
                        uvY = 0.0f;
                    }
                    else if (i == 5 || i == 4)
                    {
                        uvY = -0.5f;
                    }
                    else
                    {
                        var relativeVertexPosInUVSpace = vertices[i].z / diameter * hexWidthUV;
                        uvY = -Utils.Mod(((uvBasePos.y + relativeVertexPosInUVSpace) / HexMetrics.hexHeightToWidth / 2), 0.5f);
                    }
                    uv.Add(new Vector2(
                               -(uvBasePos.x + vertices[i].x / diameter * hexWidthUV),
                               uvY));
                }
            }
            else
            {
                triangles.AddRange(new int[]
                {
                    // Start with the preset triangles for the hex top.
                    0, 1, 2,
                    0, 2, 3,
                    0, 3, 5,
                    5, 3, 4
                });

                for (var i = 0; i < vertices.Count; i++)
                {
                    var   relativeVertexPosInUVSpace = vertices[i].z / diameter * hexWidthUV;
                    float uvY;
                    // Sometimes due to rounding the UV coordinate can end up on the wrong side of the texture
                    // for tiles at the edges of the texture. This will ensure that they appear on the correct
                    // side.
                    if ((offsetCoords.x % 2 != 0 && (offsetCoords.y + 1) % 3 == 0) && (i == 1 || i == 2))
                    {
                        uvY = -0.5f;
                    }
                    else if (offsetCoords.x % 2 != 0 && offsetCoords.y % 3 == 0 && (i == 4 || i == 5))
                    {
                        uvY = 0f;
                    }
                    else
                    {
                        uvY = -Utils.Mod(((uvBasePos.y + relativeVertexPosInUVSpace) / HexMetrics.hexHeightToWidth / 2), 0.5f);
                    }
                    uv.Add(new Vector2(
                               -(uvBasePos.x + vertices[i].x / diameter * hexWidthUV),
                               uvY));
                }
            }
        }
Exemple #6
0
 public HexPosition(HexCoords coordinates, float elevation)
 {
     Coordinates = coordinates;
     Elevation   = elevation;
 }
Exemple #7
0
 public HexPosition()
 {
     Coordinates = new HexCoords(0, 0);
     Elevation   = 0f;
 }
Exemple #8
0
        /// <summary>
        /// Remove a tile from this chunk.
        /// </summary>
        internal void RemoveTile(HexCoords coords)
        {
            tiles.RemoveAll(tile => tile.Coordinates.Equals(coords));

            Dirty = true;
        }