本文整理汇总了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);
}
}
示例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();
}