本文整理汇总了C#中TerrainData类的典型用法代码示例。如果您正苦于以下问题:C# TerrainData类的具体用法?C# TerrainData怎么用?C# TerrainData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TerrainData类属于命名空间,在下文中一共展示了TerrainData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * Speed);
if (transform.position.z >= 2 + float.Epsilon && !go)
{
go = true;
GameObject terrain;
TerrainData _terraindata = new TerrainData();
TerrainData t = gameObject.GetComponent<Terrain>().terrainData;
terrain = Terrain.CreateTerrainGameObject(t);
GameObject ingameTerrainGameObject = (GameObject)Instantiate(terrain, StartPos, Quaternion.identity);
//GenerateHeights(gameObject.GetComponent<Terrain>(), 2f);
ingameTerrainGameObject.AddComponent<MoveTerrain>();
Destroy(terrain);
Destroy(gameObject);
}
/*if (transform.position.z > 20 + float.Epsilon)
Destroy(gameObject);*/
}
示例2: getTerrain
private void getTerrain (){
if(Terrain.activeTerrain != null){
r_Terrain = Terrain.activeTerrain;
r_TerrainData = r_Terrain.terrainData;
r_TerrainPos = r_Terrain.transform.position;
}
}
示例3: CreateTerrainData
/// <summary>
/// Creates terrain data from heights.
/// </summary>
/// <param name="heightPercents">Terrain height percentages ranging from 0 to 1.</param>
/// <param name="maxHeight">The maximum height of the terrain, corresponding to a height percentage of 1.</param>
/// <param name="heightSampleDistance">The horizontal/vertical distance between height samples.</param>
/// <param name="splatPrototypes">The textures used by the terrain.</param>
/// <param name="alphaMap">Texture blending information.</param>
/// <returns>A TerrainData instance.</returns>
public static TerrainData CreateTerrainData(float[,] heightPercents, float maxHeight, float heightSampleDistance, SplatPrototype[] splatPrototypes, float[,,] alphaMap)
{
Debug.Assert((heightPercents.GetLength(0) == heightPercents.GetLength(1)) && (maxHeight >= 0) && (heightSampleDistance >= 0));
// Create the TerrainData.
var terrainData = new TerrainData();
terrainData.heightmapResolution = heightPercents.GetLength(0);
var terrainWidth = (terrainData.heightmapResolution - 1) * heightSampleDistance;
// If maxHeight is 0, leave all the heights in terrainData at 0 and make the vertical size of the terrain 1 to ensure valid AABBs.
if(!Mathf.Approximately(maxHeight, 0))
{
terrainData.size = new Vector3(terrainWidth, maxHeight, terrainWidth);
terrainData.SetHeights(0, 0, heightPercents);
}
else
{
terrainData.size = new Vector3(terrainWidth, 1, terrainWidth);
}
// Texture the terrain.
if((splatPrototypes != null) && (alphaMap != null))
{
Debug.Assert(alphaMap.GetLength(0) == alphaMap.GetLength(1));
terrainData.alphamapResolution = alphaMap.GetLength(0);
terrainData.splatPrototypes = splatPrototypes;
terrainData.SetAlphamaps(0, 0, alphaMap);
}
return terrainData;
}
示例4: OnGUI
void OnGUI()
{
tWidth = EditorGUILayout.IntField("Terrain Width", tWidth);
tHeight = EditorGUILayout.IntField("Terrain Height", tHeight);
tDepth = EditorGUILayout.IntField("Terrain Depth", tDepth);
EditorGUILayout.Separator();
cellWidth = EditorGUILayout.IntSlider("Cell Width", cellWidth, 1, 512);
cellDepth = EditorGUILayout.IntSlider("Cell Depth", cellDepth, 1, 512);
cliffLevel = EditorGUILayout.FloatField("Cliff Height", cliffLevel);
EditorGUILayout.Separator();
if (GUILayout.Button("Create"))
{
TerrainData terData = new TerrainData() { size = new Vector3(tWidth, tHeight, tDepth), name = "Map Terrain", heightmapResolution = 512, baseMapResolution = 1024 };
GameObject ter = Terrain.CreateTerrainGameObject(terData);
ter.name = "Map";
Gridmap gmap = ter.AddComponent<Gridmap>();
gmap.cellWidth = cellWidth;
gmap.cellDepth = cellDepth;
gmap.cliffHeight = cliffLevel;
isVisible = false;
this.Close();
}
else if (GUILayout.Button("Cancel"))
{
isVisible = false;
this.Close();
}
}
示例5: GetTerrainTextures
private static TextureData GetTerrainTextures(TerrainData terrainData)
{
return new TextureData
{
SplatMaps = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight),
ControlTextureResolution = terrainData.alphamapResolution
};
}
示例6: UpdateControlTextureResolution
public static void UpdateControlTextureResolution(TerrainData terrainData, int newResolution)
{
var existingData = GetTerrainTextures(terrainData);
terrainData.alphamapResolution = newResolution;
ApplyTexturesToNewTerrain(terrainData, existingData);
}
示例7: AdjustSpawnPositionForTerrainShape
/// <summary>
/// </summary>
/// <param name="terrainData"></param>
/// <param name="position">Location in the XZ plane (not the XY plane!)</param>
/// <param name="sphereRadius"></param>
/// <returns></returns>
private static Vector3 AdjustSpawnPositionForTerrainShape(TerrainData terrainData, Vector2 position, float sphereRadius)
{
var height = terrainData.GetInterpolatedHeight(position.x, position.y);
var normal = terrainData.GetInterpolatedNormal(position.x, position.y);
var offsetAlongNormal = normal * sphereRadius;
var positionOnTerrain = new Vector3(position.x, height, position.y);
return positionOnTerrain + offsetAlongNormal;
}
示例8: CreateTerrain
private TerrainData CreateTerrain()
{
TerrainData terrainData = new TerrainData ();
terrainData.size = terrainPrefab.terrainData.size;
terrainData.heightmapResolution = terrainPrefab.terrainData.heightmapHeight;
terrainData.baseMapResolution = terrainPrefab.terrainData.baseMapResolution;
terrainData.SetDetailResolution (terrainPrefab.terrainData.detailResolution, 1);
return terrainData;
}
示例9: CopyTerrainDataFromTo
void CopyTerrainDataFromTo(TerrainData tDataFrom, ref TerrainData tDataTo)
{
tDataTo.SetDetailResolution(tDataFrom.detailResolution, 8);
tDataTo.heightmapResolution = tDataFrom.heightmapResolution;
tDataTo.alphamapResolution = tDataFrom.alphamapResolution;
tDataTo.baseMapResolution = tDataFrom.baseMapResolution;
tDataTo.size = tDataFrom.size;
tDataTo.splatPrototypes = tDataFrom.splatPrototypes;
}
示例10: ApplyTexturesToNewTerrain
private static void ApplyTexturesToNewTerrain(TerrainData terrainData, TextureData data)
{
if (data.ControlTextureResolution != terrainData.alphamapResolution)
{
data.AdjustSplatMapResolution(terrainData.alphamapResolution);
}
terrainData.SetAlphamaps(0, 0, data.SplatMaps);
}
示例11: Area
public Area(TerrainData owner, Block[] blocks)
{
m_owner = owner;
foreach (Block point in blocks)
{
AddPoint(point);
}
}
示例12: GetTerrainSplatNames
public static string[] GetTerrainSplatNames(TerrainData d)
{
List<string> l = new List<string>();
for (int i = 0; i < d.splatPrototypes.Length; ++i) {
l.Add(d.splatPrototypes[i].texture.name);
}
return l.ToArray();
}
示例13: TerrainTile
public TerrainTile(Terrain terrain, TerrainData tData, Vector3 index)
{
Terrain = terrain;
TData = tData;
TCollider = terrain.GetComponent<TerrainCollider>();
Index = index;
InUse = false;
Terrain.terrainData = TData;
TCollider.terrainData = TData;
}
示例14: Awake
void Awake()
{
Debug.Log("Awake WorldMap");
MapTile tempMapTile;
BitMapDecoder bmd = new BitMapDecoder(heightmap);
terrainData = terrain.terrainData;
int heighMapWidth = terrainData.heightmapWidth;
int heighMapHeight = terrainData.heightmapHeight;
float[,] tempFloat = terrainData.GetHeights(0, 0, heighMapWidth, heighMapHeight);
tilesDictionary = new Dictionary<string, MapTile>();
for (int z = 0; z < mapSizeZ; z++ ) {
for (int x = 0; x < mapSizeX; x++) {
tempMapTile = new MapTile(x,z);
int height = BitMapDecoder.getHeightPos(x, z);
tempMapTile.setY(height);
//tempFloat[x*2+1, z*2+1] = height / 5;
tempFloat[x * 2, z*2 * 2] = (float)height / 10;
//tempFloat[x*2, z * 2+1] = height / 5;
//tempFloat[x * 2 + 1, z * 2] = height / 5;
tilesDictionary.Add(("x" + x.ToString() + "z" + z.ToString()), tempMapTile);
}
}
terrain.terrainData.SetHeights(0, 0, tempFloat);
}
示例15: Start
void Start()
{
tData = myTerrain.terrainData;
xResolution = tData.heightmapWidth;
zResolution = tData.heightmapHeight;
heights = tData.GetHeights(0, 0, xResolution, zResolution);
}