Ejemplo n.º 1
0
    /*
     * 参考资料:https://indienova.com/indie-game-development/hex-map-part-2/
     *
     *      v3     v4
     * v5 ____________ v6
     *    \ |      | /
     *   v1\|______|/v2
     *      \      /
     *       \    /
     *        \  /
     *         \/
     *        center
     */
    /// <summary>
    /// 绘制六边形
    /// </summary>
    /// <param name="cell"></param>
    private void Triangulate(HexCell cell)
    {
        Vector3 center = cell.center;

        for (HexDirectionEnum i = 0; i < HexDirectionEnum.Length; i++)
        {
            //绘制内三角
            Vector3 v1 = center + HexMetrics.GetFirstSolidCorner(i);
            Vector3 v2 = center + HexMetrics.GetSecondSolidConrner(i);

            AddTriangle(center, v1, v2);
            AddTriangleColor(cell.color, cell.color, cell.color);

            /*Vector3 bridge = HexMetrics.GetBridge( i ) ;
             * Vector3 v3 = v1 + bridge;
             * Vector3 v4 = v2 + bridge;
             *
             * AddQuad( v1 , v2 , v3 , v4 ) ;
             *
             * HexCell prevNeighbor = cell.GetNeighbor( i.Previous() ) ?? cell ;
             * HexCell neighbor = cell.GetNeighbor( i ) ?? cell ;
             * HexCell nextNeighbor = cell.GetNeighbor( i.Next() ) ?? cell ;
             *
             * Color firstColor = (cell.color + prevNeighbor.color + neighbor.color) / 3f ;
             * Color secondColor = (cell.color + neighbor.color + nextNeighbor.color) / 3f ;
             * Color bridgeColor = (cell.color + neighbor.color) * 0.5f ;
             *
             * AddQuadColor( cell.color , bridgeColor) ;
             *
             * AddTriangle( v1,center+HexMetrics.GetFirstCorner( i ),v3 );
             * AddTriangleColor( cell.color,firstColor,bridgeColor );
             *
             * AddTriangle(v2, v4, center + HexMetrics.GetSecondConrner(i));
             * AddTriangleColor(cell.color, bridgeColor, secondColor);*/

            //绘制外梯形,为了避免重复绘制,两个三角形只绘制一次
            if (i == HexDirectionEnum.TopRight || i == HexDirectionEnum.Right || i == HexDirectionEnum.BottomRight)
            {
                RightTrangulateConnection(i, cell, v1, v2);
            }
            else if (cell.GetNeighbor(i) == null)
            {
                NoNeighborConnection(i, cell, v1, v2);
            }
        }
    }