示例#1
0
 void Start()
 {
     if (HexTerrain.Instance != null)
     {
         _gridPosition = HexTerrain.Instance.RegisterPawn(this);
         if (_gridPosition.HasValue)
         {
             Vector3 newPosition = HexagonUtils.ConvertHexaSpaceToOrthonormal(_gridPosition.Value);
             newPosition.y      = HexTerrain.Instance.HexData[_gridPosition.Value].Height;
             transform.position = newPosition;
         }
     }
 }
示例#2
0
    public void BuildChunks()
    {
        Debug.Log("Build chunk array");

        // Create Chunk array
        _chunks = new Chunk[ChunkCol * ChunkRow];
        for (int i = 0; i < ChunkCol; i++)
        {
            for (int j = 0; j < ChunkRow; j++)
            {
                _chunks[i * ChunkRow + j] = MakeNewChunk(HexagonUtils.ConvertHexaSpaceToOrthonormal(new Vector2i(j * chunkWidth, i * chunkLength)),
                                                         new Vector2i(j * chunkWidth, i * chunkLength));
            }
        }
    }
示例#3
0
    /// <summary>
    /// Add the geometry of this Hexagon inside the MeshData structure of the calling Chunk.
    /// </summary>
    /// <param name="meshData">MeshData structure to be filed </param>
    /// <param name="chunkOffSet">world offset of the parent chunk </param>
    /// <param name="coordinate">2d grid coordinate of this hexa relative to its chunk </param>
    /// <param name="neighbours"> Array containing the 6 neighbours of this hex, some can be null</param>
    public void AddToChunk(ref Chunk.MeshData meshData, Vector3 chunkOffSet, Vector2i coordinate,
                           Hexagon[] neighbours, HexagonTypeData types)
    {
        //TODO: compute top vertex position of this hexagon at start to avoid multiple recomputation.

        // Compute hexagon position.
        Vector3 coordinateOffset = HexagonUtils.ConvertHexaSpaceToOrthonormal(coordinate) + chunkOffSet;

        GenerateTop(ref meshData, coordinateOffset, types, neighbours);
        for (int i = 0; i < 6; i++)
        {
            if (IsSideVisible(neighbours[i], types))
            {
                GenerateSide(ref meshData, coordinateOffset, i, neighbours, types);
            }
        }
    }