• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Terrain类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnityEngine.Terrain的典型用法代码示例。如果您正苦于以下问题:C# Terrain类的具体用法?C# Terrain怎么用?C# Terrain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Terrain类属于UnityEngine命名空间,在下文中一共展示了Terrain类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:28,代码来源:DetailMeshWizard.cs


示例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;
        }
开发者ID:GamesDesignArt,项目名称:unity3d_nav_critterai,代码行数:29,代码来源:TerrainUtil.cs


示例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();
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:7,代码来源:ExportRawHeightmap.cs


示例4: 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();
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:25,代码来源:DetailTextureWizard.cs


示例5: 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;
	}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:7,代码来源:ExportSplatmap.cs


示例6: 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);
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:8,代码来源:TerrainEditorUtility.cs


示例7: 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));
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:17,代码来源:DynamicGI.cs


示例8: 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();
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:8,代码来源:ImportRawHeightmap.cs


示例9: 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);
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:9,代码来源:TerrainEditorUtility.cs


示例10: Setup

 public override void Setup(Renderer render, IFPV_Object parent)
 {
     terrain = GetComponent<Terrain>();
     _parent = parent;
     _render = render;
     _originalLayer = gameObject.layer;
     isVisible = true;
     viewChanged = false;
 }
开发者ID:jimmikaelkael,项目名称:-Unity-First-Person-View,代码行数:9,代码来源:FPV_Renderer_Terrain.cs


示例11: Init

        public void Init(Terrain _terrain, MapDataGround.Tile[,] tiles, float[,] height, byte[,] zones)
        {
            InitGlobal();
            InitWorld();

            terrain = _terrain;

            InitTerrain(tiles, height, zones);
        }
开发者ID:cyanpunk,项目名称:muonline,代码行数:9,代码来源:MapTerrain.cs


示例12: 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);
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:10,代码来源:TerrainEditorUtility.cs


示例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;		
	}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:10,代码来源:ImportSplatmap.cs


示例14: Initialize

        public static void Initialize()
        {
            if (Loaded == false) {

                LSDatabase database = LSFSettingsManager.GetSettings ().Database;
                _currentDatabase = database;
                Loaded = true;
                LockstepManager.Setup();
            }
            Terrain = GameObject.FindObjectOfType<Terrain> ();
        }
开发者ID:citizenparker,项目名称:Lockstep-Framework,代码行数:11,代码来源:LSDatabaseManager.cs


示例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++;
			}
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:54,代码来源:TreePainter.cs


示例16: 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 (terrain == null)
     {
         throw new ArgumentNullException("terrain");
     }
     if (terrain.terrainData == null)
     {
         throw new ArgumentException("Invalid terrainData.");
     }
     UpdateMaterialsForTerrain(terrain, new Rect(0f, 0f, 1f, 1f));
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:21,代码来源:DynamicGI.cs


示例17: IsValidTree

 private static bool IsValidTree(GameObject tree, int prototypeIndex, Terrain terrain)
 {
   if ((Object) tree == (Object) null)
     return false;
   TreePrototype[] treePrototypes = terrain.terrainData.treePrototypes;
   for (int index = 0; index < treePrototypes.Length; ++index)
   {
     if (index != prototypeIndex && (Object) treePrototypes[index].m_Prefab == (Object) tree)
       return false;
   }
   return true;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:12,代码来源:TreeWizard.cs


示例18: InitializeDefaults

		internal new void InitializeDefaults(Terrain terrain)
		{
			this.m_Terrain = terrain;
			this.m_TerrainWidth = base.terrainData.size.x;
			this.m_TerrainHeight = base.terrainData.size.y;
			this.m_TerrainLength = base.terrainData.size.z;
			this.m_HeightmapResolution = base.terrainData.heightmapResolution;
			this.m_DetailResolution = base.terrainData.detailResolution;
			this.m_DetailResolutionPerPatch = base.terrainData.detailResolutionPerPatch;
			this.m_ControlTextureResolution = base.terrainData.alphamapResolution;
			this.m_BaseTextureResolution = base.terrainData.baseMapResolution;
			this.OnWizardUpdate();
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:13,代码来源:SetResolutionWizard.cs


示例19: InitializeData

 private void InitializeData(Terrain terrain, int index)
 {
   this.m_Terrain = terrain;
   this.m_Index = index;
   SplatPrototype splatPrototype = index != -1 ? this.m_Terrain.terrainData.splatPrototypes[index] : new SplatPrototype();
   this.m_Texture = splatPrototype.texture;
   this.m_NormalMap = splatPrototype.normalMap;
   this.m_TileSize = splatPrototype.tileSize;
   this.m_TileOffset = splatPrototype.tileOffset;
   this.m_Specular = splatPrototype.specular;
   this.m_Metallic = splatPrototype.metallic;
   this.m_Smoothness = splatPrototype.smoothness;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:13,代码来源:TerrainSplatEditor.cs


示例20: TriangulateSurface

        public static TriangleMesh TriangulateSurface(Terrain terrain
            , float xmin, float zmin, float xmax, float zmax
            , float resolution
            , float yOffset)
        {
            if (terrain == null || terrain.terrainData == null 
                || resolution <= 0
                || xmin > xmax || zmin > zmax)
            {
                return null;
            }

            int xCount;
            int zCount;
            Vector3 scale = DeriveScale(terrain, resolution, out xCount, out zCount);

            Vector3 origin = terrain.transform.position;

            /*
             * We are generating part of a larger mesh.  The vertices must match that of the larger
             * mesh.
             * 
             * Convert input values to local grid space.
             * Clamp to the heightfield bounds.
             * Convert back to worldspace.
             */
            xmin = origin.x + Mathf.Max(0, Mathf.Floor((xmin - origin.x) / scale.x)) * scale.x;
            zmin = origin.z + Mathf.Max(0, Mathf.Floor((zmin - origin.z) / scale.z)) * scale.z;
            xmax = origin.x + Mathf.Min(xCount, Mathf.Ceil((xmax - origin.x) / scale.x)) * scale.x;
            zmax = origin.z + Mathf.Min(xCount, Mathf.Ceil((zmax - origin.z) / scale.z)) * scale.z;

            if (xmin + scale.x > xmax || zmin + scale.z > zmax)
                // Triangulation zone is too small.
                return null;

            // Everyting is already snapped to the grid.  But there may be floating point errors.
            // So round it.
            xCount = Mathf.RoundToInt((xmax - xmin) / scale.x);
            zCount = Mathf.RoundToInt((zmax - zmin) / scale.z);

            TriangleMesh m = new TriangleMesh(xCount * zCount, (xCount - 1) * (zCount - 1) * 2);

            TriangulateSurface(terrain
                , new Vector3(xmin, origin.y, zmin)
                , scale
                , xCount, zCount
                , yOffset
                , m);

            return m;
        }
开发者ID:BibleUs,项目名称:critterai,代码行数:51,代码来源:TerrainUtil.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.TextAsset类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.SpriteRenderer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap