本文整理汇总了C#中UnityEngine.Terrain.SampleHeight方法的典型用法代码示例。如果您正苦于以下问题:C# Terrain.SampleHeight方法的具体用法?C# Terrain.SampleHeight怎么用?C# Terrain.SampleHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Terrain
的用法示例。
在下文中一共展示了Terrain.SampleHeight方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartBuilding
public void StartBuilding(Player player) {
owner = player;
isBuilt = true;
creationProgress = 0;
spawnPoint = transform.position;
while(this.GetComponent<Collider>().bounds.Contains (spawnPoint))
spawnPoint += transform.forward;
terrain = Terrain.activeTerrain;
spawnPoint.y = terrain.SampleHeight(spawnPoint) + unit.GetComponent<Renderer>().bounds.size.y;
}
示例2: RandomPositionOnTerrain
private Vector3 RandomPositionOnTerrain(Terrain terrain, int offset = 0)
{
var terrainPos = terrain.transform.position;
var size = terrain.terrainData.size;
var pos = Vector3.zero;
pos.x = Random.Range(terrainPos.x + offset, terrainPos.x + size.x - offset);
pos.z = Random.Range(terrainPos.z + offset, terrainPos.z + size.z - offset);
pos.y = terrain.SampleHeight(pos);
return pos;
}
示例3: DrawBrush
public void DrawBrush(Vector3 pos, float radius, Terrain terrain, Color color, float thickness=3f, int numCorners=32)
{
//incline is the height delta in one unit distance
Handles.color = color;
Vector3[] corners = new Vector3[numCorners+1];
float step = 360f/numCorners;
for (int i=0; i<=corners.Length-1; i++)
{
corners[i] = new Vector3( Mathf.Sin(step*i*Mathf.Deg2Rad), 0, Mathf.Cos(step*i*Mathf.Deg2Rad) ) * radius + pos;
corners[i].y = terrain.SampleHeight(corners[i]);
}
Handles.DrawAAPolyLine(thickness, corners);
}
示例4: InitializePosition
public Vector3 InitializePosition(Terrain terrain)
{
var terrainStartPosition = terrain.GetPosition ();
var xPosition = (terrainStartPosition.x + terrain.terrainData.size.x) / 2.0f;
var zPosition = (terrainStartPosition.z + terrain.terrainData.size.z) / 2.0f;
Vector3 airplanePosition = new Vector3 ();
airplanePosition.x = xPosition;
airplanePosition.z = zPosition;
airplanePosition.y = terrain.SampleHeight (airplanePosition) + StartHeightDistanceBetweenTerrainAdnAirplane;
gameObject.transform.position = airplanePosition;
return airplanePosition;
}
示例5: AddGrave
public void AddGrave(int x, int y, Terrain terrain)
{
TerrainData data = terrain.terrainData;
float xNormalized = x/(float)data.size.x;
float yNormalized = x/(float)data.size.y;
float scaleRatio = Random.Range(0.8f,1.2f);
Vector3 spawnPos = Vector3.zero;
spawnPos.x = x + terrain.GetPosition().x;
spawnPos.z = y + terrain.GetPosition().z;
spawnPos.y = terrain.SampleHeight(spawnPos)-0.1f;
GameObject go = GameObject.Instantiate(gravePrefabs[Random.Range(0,gravePrefabs.Length)],spawnPos,Quaternion.identity) as GameObject;
go.transform.localScale = Vector3.one * scaleRatio;
go.transform.parent = terrain.transform;
RaycastHit hitInfo;
if(Physics.Linecast(go.transform.position + Vector3.up,go.transform.position - Vector3.up * 50.0f,out hitInfo)){
go.transform.up = hitInfo.normal;
}
go.transform.RotateAround(go.transform.up,Random.Range(0.0f,360.0f));
}
示例6: SetWaterYCoordinate
/// <summary>
/// Create heights and assign it to the passed terrain
/// </summary>
/// <param name="terrain">Terrain</param>
public void SetWaterYCoordinate(Terrain terrain)
{
Vector3 lowestPoint = new Vector3(100f, 100f, 100f);
for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
{
for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
{
Vector3 worldPoint = terrain.transform.TransformPoint(new Vector3(i, 0f, k));
float height = terrain.SampleHeight(worldPoint);
if (height < lowestPoint.z)
{
lowestPoint = new Vector3(i, k, height);
}
}
}
//Debug.Log("Lowest point:" + lowestPoint.x + ", " + lowestPoint.y + ", " + lowestPoint.z);
// Set the water at this plus the water depth
Vector3 waterPosition = Water.transform.position;
waterPosition.y = lowestPoint.z + MaxWaterHeight;
Water.transform.position = waterPosition;
}
示例7: TriangulateSurface
private static void TriangulateSurface(Terrain terrain
, Vector3 origin
, Vector3 scale
, int xCount
, int zCount
, float yOffset
, TriangleMesh buffer)
{
// Create the vertices by sampling the terrain.
for (int ix = 0; ix < xCount; ix++)
{
float x = origin.x + ix * scale.x;
for (int iz = 0; iz < zCount; iz++)
{
float z = origin.z + iz * scale.z;
Vector3 pos = new Vector3(x, origin.y, z);
pos.y += terrain.SampleHeight(pos) + yOffset;
buffer.verts[buffer.vertCount] = pos;
buffer.vertCount++;
}
}
// Triangulate surface sample points.
for (int ix = 0; ix < xCount - 1; ix++)
{
for (int iz = 0; iz < zCount - 1; iz++)
{
int i = iz + (ix * zCount);
int irow = i + zCount;
buffer.tris[buffer.triCount * 3 + 0] = i;
buffer.tris[buffer.triCount * 3 + 1] = irow + 1;
buffer.tris[buffer.triCount * 3 + 2] = irow;
buffer.triCount++;
buffer.tris[buffer.triCount * 3 + 0] = i;
buffer.tris[buffer.triCount * 3 + 1] = i + 1;
buffer.tris[buffer.triCount * 3 + 2] = irow + 1;
buffer.triCount++;
}
}
}
示例8: CalculateHeight
private bool CalculateHeight(Terrain ter, int x, int y, DetailSettings ds)
{
if (ds.MinimumHeight == 0 && ds.MaximumHeight == 0)
return true;
float xDim = x * xUnit;
float yDim = y * yUnit;
Vector3 realPosition = new Vector3(yDim, 0, xDim);
float positionY = ter.SampleHeight(realPosition);
if (positionY < ds.MinimumHeight || positionY > ds.MaximumHeight)
{
return false;
}
return true;
}
示例9: SetSceneVerts
public void SetSceneVerts(Terrain t)
{
if (SceneVerts == null) SceneVerts = new Vector3[4];
Vector3 scale = new Vector3(width, 1, depth);
float tl = t.SampleHeight(center + new Vector3(-width / 2.0f, 0, depth / 2.0f));
float tr = t.SampleHeight(center + new Vector3(width / 2.0f, 0, depth / 2.0f));
float bl = t.SampleHeight(center + new Vector3(-width / 2.0f, 0, -depth / 2.0f));
float br = t.SampleHeight(center + new Vector3(width / 2.0f, 0, -depth / 2.0f));
SceneVerts[0] = center + new Vector3(-width / 2.0f, bl - center.y, -depth / 2.0f);
SceneVerts[1] = center + new Vector3(-width / 2.0f, tl - center.y, depth / 2.0f);
SceneVerts[2] = center + new Vector3(width / 2.0f, tr - center.y, depth / 2.0f);
SceneVerts[3] = center + new Vector3(width / 2.0f, br - center.y, -depth / 2.0f);
}
示例10: CellIsSmooth
private bool CellIsSmooth(GridmapCell c, Terrain t)
{
// grab 4-corners + center heights
float ch = t.SampleHeight(c.center);
float tl = t.SampleHeight(c.center + new Vector3(-cellWidth / 2.0f, 0, cellDepth / 2.0f));
float tr = t.SampleHeight(c.center + new Vector3(cellWidth / 2.0f, 0, cellDepth / 2.0f));
float bl = t.SampleHeight(c.center + new Vector3(-cellWidth / 2.0f, 0, -cellDepth / 2.0f));
float br = t.SampleHeight(c.center + new Vector3(cellWidth / 2.0f, 0, -cellDepth / 2.0f));
// check if center diff is too big:
if (Mathf.Abs(ch - tl) > cliffHeight ||
Mathf.Abs(ch - tr) > cliffHeight ||
Mathf.Abs(ch - bl) > cliffHeight ||
Mathf.Abs(ch - br) > cliffHeight)
return false;
// check if top-left diff is too big:
if (Mathf.Abs(tl - tr) > cliffHeight ||
Mathf.Abs(tl - bl) > cliffHeight)
return false;
// check if bot-right diff is too big:
if (Mathf.Abs(br - tr) > cliffHeight ||
Mathf.Abs(br - bl) > cliffHeight)
return false;
return true;
}
示例11: SpawnGameOverSwitch
public void SpawnGameOverSwitch(Terrain terrain)
{
Vector3 spawnPos = terrain.GetPosition() + new Vector3(128.0f, 0.0f, 256.0f);
GameObject go = GameObject.Instantiate(gameOverSwitchPrefab,spawnPos,Quaternion.Euler(new Vector3(0.0f,0.0f,180.0f))) as GameObject;
UserInterface.SetText2("Find the light, and be free...");
Vector3 pos = go.transform.position;
pos.y = terrain.SampleHeight(go.transform.position) + 0.8f;
go.transform.position = pos;
}