当前位置: 首页>>代码示例>>C#>>正文


C# TerrainData.GetBlock方法代码示例

本文整理汇总了C#中TerrainData.GetBlock方法的典型用法代码示例。如果您正苦于以下问题:C# TerrainData.GetBlock方法的具体用法?C# TerrainData.GetBlock怎么用?C# TerrainData.GetBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TerrainData的用法示例。


在下文中一共展示了TerrainData.GetBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: _findAreas

    private void _findAreas(TerrainData data)
    {
        HashSet<Block> visited = new HashSet<Block>();

        int width = data.Width;
        int height = data.Height;

        LinkedList<Area> areas = new LinkedList<Area>();

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Block block = data.GetBlock(new Point(x, y));
                if (block.Value > 0 && !visited.Contains(block))
                {
                    Area newArea = _floodFillArea(block, visited);
                    if (newArea != null)
                        areas.AddLast(newArea);
                }
            }
        }

        foreach (Area area in areas)
        {
            data.AddArea(area);
        }
    }
开发者ID:bpeake13,项目名称:GGJ2016,代码行数:28,代码来源:TerrainGenerator.cs

示例2: _generateMesh

    private void _generateMesh(TerrainData data)
    {
        Vector3 startPosition = transform.position - new Vector3(m_data.Width, 0, m_data.Height) * m_boxSize * 0.5f;
        Vector3 step = new Vector3(m_boxSize, 0, m_boxSize);

        int width = data.Width;
        int height = data.Height;
        
        ControlNode[,] nodes = new ControlNode[width,height];

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Vector3 offset = startPosition + new Vector3(step.x * x, 0.0f, step.z * y);
                nodes[x, y] = new ControlNode(offset, data.GetBlock(new Point(x, y)), m_boxSize);
            }
        }

        LinkedList<Square> squares = new LinkedList<Square>();

        for (int y = 0; y < height - 1; y++)
        {
            for (int x = 0; x < width - 1; x++)
            {
                ControlNode bottomLeft = nodes[x, y];
                ControlNode bottomRight = nodes[x + 1, y];
                ControlNode topLeft = nodes[x, y + 1];
                ControlNode topRight = nodes[x + 1, y + 1];

                Square square = new Square(topLeft, topRight, bottomLeft, bottomRight);
                squares.AddLast(square);
            }
        }

        LinkedList<Vector3> verticies = new LinkedList<Vector3>();
        LinkedList<int> indicies = new LinkedList<int>();

        foreach (Square square in squares)
        {
            _buildSquare(square, verticies, indicies);
        } 

        Mesh mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;

        mesh.vertices = verticies.ToArray();
        mesh.triangles = indicies.ToArray();
        mesh.RecalculateNormals();
    }
开发者ID:bpeake13,项目名称:GGJ2016,代码行数:50,代码来源:GeneratedTerrain.cs


注:本文中的TerrainData.GetBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。