本文整理汇总了C#中UnityEngine.Terrain类的典型用法代码示例。如果您正苦于以下问题:C# Terrain类的具体用法?C# Terrain怎么用?C# Terrain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Terrain类属于UnityEngine命名空间,在下文中一共展示了Terrain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeDefaults
internal void InitializeDefaults(Terrain terrain, int index)
{
this.m_Terrain = terrain;
this.m_PrototypeIndex = index;
DetailPrototype detailPrototype = this.m_PrototypeIndex != -1 ? this.m_Terrain.terrainData.detailPrototypes[this.m_PrototypeIndex] : new DetailPrototype();
this.m_Detail = detailPrototype.prototype;
this.m_NoiseSpread = detailPrototype.noiseSpread;
this.m_MinWidth = detailPrototype.minWidth;
this.m_MaxWidth = detailPrototype.maxWidth;
this.m_MinHeight = detailPrototype.minHeight;
this.m_MaxHeight = detailPrototype.maxHeight;
this.m_HealthyColor = detailPrototype.healthyColor;
this.m_DryColor = detailPrototype.dryColor;
switch (detailPrototype.renderMode)
{
case DetailRenderMode.GrassBillboard:
Debug.LogError((object) "Detail meshes can't be rendered as billboards");
this.m_RenderMode = DetailMeshRenderMode.Grass;
break;
case DetailRenderMode.VertexLit:
this.m_RenderMode = DetailMeshRenderMode.VertexLit;
break;
case DetailRenderMode.Grass:
this.m_RenderMode = DetailMeshRenderMode.Grass;
break;
}
this.OnWizardUpdate();
}
示例2: DeriveScale
public static Vector3 DeriveScale(Terrain terrain, float resolution
, out int widthCount, out int depthCount)
{
widthCount = 0;
depthCount = 0;
if (terrain == null || terrain.terrainData == null || resolution <= 0)
return Vector3.zero;
Vector3 scale = terrain.terrainData.heightmapScale;
widthCount = terrain.terrainData.heightmapWidth;
depthCount = terrain.terrainData.heightmapHeight;
if (resolution > 0 && resolution < 1)
{
Vector3 size = terrain.terrainData.size;
widthCount = Mathf.FloorToInt(size.x / scale.x * resolution);
depthCount = Mathf.FloorToInt(size.z / scale.z * resolution);
scale.x = size.x / (float)widthCount;
scale.z = size.z / (float)depthCount;
// For the vertices along the maximum bounds...
widthCount++;
depthCount++;
}
return scale;
}
示例3: InitializeDefaults
private void InitializeDefaults(Terrain terrain)
{
base.m_Terrain = terrain;
object[] objArray1 = new object[] { "Width ", terrain.terrainData.heightmapWidth, " Height ", terrain.terrainData.heightmapHeight };
base.helpString = string.Concat(objArray1);
this.OnWizardUpdate();
}
示例4: RemoveTree
internal static void RemoveTree(Terrain terrain, int index)
{
TerrainData terrainData = terrain.terrainData;
if (terrainData == null)
{
return;
}
Undo.RegisterCompleteObjectUndo(terrainData, "Remove tree");
terrainData.RemoveTreePrototype(index);
}
示例5: InitializeDefaults
internal void InitializeDefaults(Terrain terrain, int index)
{
this.m_Terrain = terrain;
this.m_PrototypeIndex = index;
DetailPrototype detailPrototype;
if (this.m_PrototypeIndex == -1)
{
detailPrototype = new DetailPrototype();
detailPrototype.renderMode = DetailRenderMode.GrassBillboard;
}
else
{
detailPrototype = this.m_Terrain.terrainData.detailPrototypes[this.m_PrototypeIndex];
}
this.m_DetailTexture = detailPrototype.prototypeTexture;
this.m_MinWidth = detailPrototype.minWidth;
this.m_MaxWidth = detailPrototype.maxWidth;
this.m_MinHeight = detailPrototype.minHeight;
this.m_MaxHeight = detailPrototype.maxHeight;
this.m_NoiseSpread = detailPrototype.noiseSpread;
this.m_HealthyColor = detailPrototype.healthyColor;
this.m_DryColor = detailPrototype.dryColor;
this.m_Billboard = (detailPrototype.renderMode == DetailRenderMode.GrassBillboard);
this.OnWizardUpdate();
}
示例6: OnWizardUpdate
void OnWizardUpdate() {
this.helpString = "This tool exports the splatmap (layer weight texture) of a terrain to a PNG image.\n"+
"Optionally, the alpha channel is saved to a separate image.\n";
if( Selection.activeGameObject != null ) this.terrain = Selection.activeGameObject.GetComponent<Terrain>();
if(this.terrain == null) this.terrain = GameObject.FindObjectOfType(typeof(Terrain)) as Terrain;
this.isValid = this.terrain != null && this.terrain.terrainData != null;
}
示例7: RemoveDetail
internal static void RemoveDetail(Terrain terrain, int index)
{
TerrainData terrainData = terrain.terrainData;
if ((Object) terrainData == (Object) null)
return;
Undo.RegisterCompleteObjectUndo((Object) terrainData, "Remove detail object");
terrainData.RemoveDetailPrototype(index);
}
示例8: UpdateMaterials
/// <summary>
/// <para>Schedules an update of the albedo and emissive textures of a system that contains the renderer or the terrain.</para>
/// </summary>
/// <param name="renderer">The Renderer to use when searching for a system to update.</param>
/// <param name="terrain">The Terrain to use when searching for systems to update.</param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public static void UpdateMaterials(Terrain terrain)
{
if ((Object) terrain == (Object) null)
throw new ArgumentNullException("terrain");
if ((Object) terrain.terrainData == (Object) null)
throw new ArgumentException("Invalid terrainData.");
DynamicGI.UpdateMaterialsForTerrain(terrain, new Rect(0.0f, 0.0f, 1f, 1f));
}
示例9: InitializeImportRaw
internal void InitializeImportRaw(Terrain terrain, string path)
{
base.m_Terrain = terrain;
this.m_Path = path;
this.PickRawDefaults(this.m_Path);
base.helpString = "Raw files must use a single channel and be either 8 or 16 bit.";
this.OnWizardUpdate();
}
示例10: RemoveDetail
internal static void RemoveDetail(Terrain terrain, int index)
{
TerrainData terrainData = terrain.terrainData;
if (terrainData != null)
{
Undo.RegisterCompleteObjectUndo(terrainData, "Remove detail object");
terrainData.RemoveDetailPrototype(index);
}
}
示例11: Setup
public override void Setup(Renderer render, IFPV_Object parent)
{
terrain = GetComponent<Terrain>();
_parent = parent;
_render = render;
_originalLayer = gameObject.layer;
isVisible = true;
viewChanged = false;
}
示例12: Init
public void Init(Terrain _terrain, MapDataGround.Tile[,] tiles, float[,] height, byte[,] zones)
{
InitGlobal();
InitWorld();
terrain = _terrain;
InitTerrain(tiles, height, zones);
}
示例13: OnWizardUpdate
void OnWizardUpdate() {
this.helpString = "This tool replaces the selected terrain's splatmap (layer weight texture) with another image.\n\n" +
"The texture format must be uncompressed (set to \"Truecolor\" in inspector).\n\n" +
"This tool cannot add or remove texture layers. The terrain must have all its layers defined\n" +
"before importing. If only 2 layers are present, just the red and green channels are imported.\n";
if( Selection.activeGameObject != null ) this.terrain = Selection.activeGameObject.GetComponent<Terrain>();
if(this.terrain == null) this.terrain = GameObject.FindObjectOfType(typeof(Terrain)) as Terrain;
this.isValid = this.newSplatmap != null && this.terrain != null && this.terrain.terrainData != null;
}
示例14: Initialize
public static void Initialize()
{
if (Loaded == false) {
LSDatabase database = LSFSettingsManager.GetSettings ().Database;
_currentDatabase = database;
Loaded = true;
LockstepManager.Setup();
}
Terrain = GameObject.FindObjectOfType<Terrain> ();
}
示例15: PlaceTrees
public static void PlaceTrees(Terrain terrain, float xBase, float yBase)
{
if (terrain.terrainData.treePrototypes.Length == 0)
{
return;
}
TreePainter.selectedTree = Mathf.Min(TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData) - 1, TreePainter.selectedTree);
if (!TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, TreePainter.selectedTree))
{
return;
}
int num = 0;
TreeInstance instance = default(TreeInstance);
instance.position = new Vector3(xBase, 0f, yBase);
instance.color = TreePainter.GetTreeColor();
instance.lightmapColor = Color.white;
instance.prototypeIndex = TreePainter.selectedTree;
instance.heightScale = TreePainter.GetTreeHeight();
instance.widthScale = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale);
instance.rotation = TreePainter.GetTreeRotation();
bool flag = Event.current.type == EventType.MouseDrag || TreePainter.brushSize > 1f;
if (!flag || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, TreePainter.spacing))
{
terrain.AddTreeInstance(instance);
num++;
}
Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, TreePainter.selectedTree);
prototypeExtent.y = 0f;
float num2 = TreePainter.brushSize / (prototypeExtent.magnitude * TreePainter.spacing * 0.5f);
int num3 = (int)(num2 * num2 * 0.5f);
num3 = Mathf.Clamp(num3, 0, 100);
int num4 = 1;
while (num4 < num3 && num < num3)
{
Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
insideUnitCircle.x *= TreePainter.brushSize / terrain.terrainData.size.x;
insideUnitCircle.y *= TreePainter.brushSize / terrain.terrainData.size.z;
Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y);
if (position.x >= 0f && position.x <= 1f && position.z >= 0f && position.z <= 1f && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, TreePainter.selectedTree, TreePainter.spacing * 0.5f))
{
instance = default(TreeInstance);
instance.position = position;
instance.color = TreePainter.GetTreeColor();
instance.lightmapColor = Color.white;
instance.prototypeIndex = TreePainter.selectedTree;
instance.heightScale = TreePainter.GetTreeHeight();
instance.widthScale = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale);
instance.rotation = TreePainter.GetTreeRotation();
terrain.AddTreeInstance(instance);
num++;
}
num4++;
}
}