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

C# TerrainData类代码示例

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

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



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


示例2: getTerrain

	private void getTerrain (){
		if(Terrain.activeTerrain != null){
			r_Terrain = Terrain.activeTerrain;
			r_TerrainData = r_Terrain.terrainData;
			r_TerrainPos = r_Terrain.transform.position;
		}
	}
开发者ID:Backman,项目名称:Hellbound,代码行数:7,代码来源:GetDominantTexture.cs


示例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;
	}
开发者ID:ozonexo3,项目名称:FAForeverMapEditor,代码行数:43,代码来源:GameObjectUtils.cs


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


示例5: GetTerrainTextures

 private static TextureData GetTerrainTextures(TerrainData terrainData)
 {
     return new TextureData
            {
                SplatMaps = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight),
                ControlTextureResolution = terrainData.alphamapResolution
            };
 }
开发者ID:JWroe,项目名称:UnityTerrainToolkit,代码行数:8,代码来源:TerrainTextureToolkit.cs


示例6: UpdateControlTextureResolution

    public static void UpdateControlTextureResolution(TerrainData terrainData, int newResolution)
    {
        var existingData = GetTerrainTextures(terrainData);

        terrainData.alphamapResolution = newResolution;

        ApplyTexturesToNewTerrain(terrainData, existingData);
    }
开发者ID:JWroe,项目名称:UnityTerrainToolkit,代码行数:8,代码来源:TerrainTextureToolkit.cs


示例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;
    }
开发者ID:alex-davidson,项目名称:UnityPlayground,代码行数:15,代码来源:InitialSpawnBehaviour.cs


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


示例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;
 }
开发者ID:hayio,项目名称:run-human-run,代码行数:9,代码来源:TerrainManager.cs


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


示例11: Area

 public Area(TerrainData owner, Block[] blocks)
 {
     m_owner = owner;
     
     foreach (Block point in blocks)
     {
         AddPoint(point);
     }
 }
开发者ID:bpeake13,项目名称:GGJ2016,代码行数:9,代码来源:Area.cs


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


示例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;
    }
开发者ID:nsettnes,项目名称:TRACE-Turbulence,代码行数:11,代码来源:TerrainTile.cs


示例14: createMesh

    public static Mesh createMesh(TerrainData t, Vector3 terrainPosition)
    {
        Mesh m = new Mesh();

        int w = t.heightmapWidth;
        int h = t.heightmapHeight;
        Vector3 meshScale = t.size;
        int tRes = 2;
        meshScale = new Vector3(meshScale.x / (w - 1) * tRes, meshScale.y, meshScale.z / (h - 1) * tRes);

        float[,] tData = t.GetHeights(0, 0, w, h);

        w = (w - 1) / tRes + 1;
        h = (h - 1) / tRes + 1;

        Vector3[] tVertices = new Vector3[w * h];

        int[] tPolys;

        tPolys = new int[(w - 1) * (h - 1) * 6];

        // Build vertices
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                tVertices[y * w + x] = Vector3.Scale(meshScale, new Vector3(-y, tData[x * tRes, y * tRes], x)) + terrainPosition;
            }
        }

        int index = 0;

        // Build triangle indices: 3 indices into vertex array for each triangle
        for (int y = 0; y < h - 1; y++)
        {
            for (int x = 0; x < w - 1; x++)
            {
                // For each grid cell output two triangles
                tPolys[index++] = (y * w) + x;
                tPolys[index++] = ((y + 1) * w) + x;
                tPolys[index++] = (y * w) + x + 1;

                tPolys[index++] = ((y + 1) * w) + x;
                tPolys[index++] = ((y + 1) * w) + x + 1;
                tPolys[index++] = (y * w) + x + 1;
            }
        }

        m.vertices = tVertices;
        m.triangles = tPolys;
        m.subMeshCount = 1;

        return m;
    }
开发者ID:Raysangar,项目名称:BadPrincess-LevelEditor,代码行数:54,代码来源:ExportToPhysXScript.cs


示例15: _generateNoise

 private void _generateNoise(System.Random rng, TerrainData data)
 {
     int width = data.Width;
     int height = data.Height;
     for (int y = 0; y < height; y++)
     {
         for(int x = 0; x < width; x++)
         {
             data.SetValue(x, y, rng.NextDouble() < m_randomFillChance ? 1 : 0);
         }
     }
 }
开发者ID:bpeake13,项目名称:GGJ2016,代码行数:12,代码来源:TerrainGenerator.cs


示例16: Awake

    private void Awake()
    {
        var terrain = GetComponent<Terrain>();

        var map = ReadMap(Filename);
        //var map = ReadMap(string.Format("{0}_{1}", 0, 0));
        //var map = GetRandomizedMap(33, 33, 0.2f);

        var data = new TerrainData { size = new Vector3(100f, 100f, 100f), heightmapResolution = 33 };

        terrain.terrainData = data;
        terrain.terrainData.SetHeights(0, 0, map);
    }
开发者ID:bodedoctor,项目名称:topresearch,代码行数:13,代码来源:FromBitmap.cs


示例17: GenerateTerrain

	public void GenerateTerrain(TerrainData terrainData, float tileSize)
	{
		if(disableProceduralTerrain)
			return;

		_heightMap = new float[terrainData.heightmapWidth, terrainData.heightmapHeight];

		float width_2 = terrainData.heightmapWidth*0.5f;
		float height_2 = terrainData.heightmapHeight*0.5f;

		float aW = MathHelpers.RandomFromVec2(aWMinMax);
		float bW = MathHelpers.RandomFromVec2(bWMinMax);
		float cW = MathHelpers.RandomFromVec2(cWMinMax);
		float dW = MathHelpers.RandomFromVec2(dWMinMax);
		
		float bH = MathHelpers.RandomFromVec2(bHMinMax);
		float cH = MathHelpers.RandomFromVec2(cHMinMax);
	

		for (int i = 0; i < terrainData.heightmapWidth; i++)
		{
			for (int k = 0; k < terrainData.heightmapHeight; k++)
			{
				float xW = (float)(i - width_2);
				float xH = (float)(k - height_2);
				float heightAdjustW = aW*Mathf.Exp(- (Mathf.Pow((xW -bW),2)/(2*Mathf.Pow(cW,2)) + Mathf.Pow((xH-bH),2)/(2*Mathf.Pow(cH,2)))) + dW;

				_heightMap[i, k] = heightAdjustW +  MathHelpers.RandomFromVec2( perlinNoiseAmpMinMax )*Mathf.PerlinNoise(((float)i / (float)terrainData.heightmapWidth) * tileSize, ((float)k / (float)terrainData.heightmapHeight) * tileSize);
			}
		}

		terrainData.SetHeights(0, 0, _heightMap);

		SplatPrototype groundProto = new SplatPrototype();
		groundProto.texture = terrainTexture;
		groundProto.tileOffset = new Vector2(0f,0f);
		groundProto.tileSize = new Vector2(10f,10f);

		SplatPrototype snowProto = new SplatPrototype();
		snowProto.texture = snowTexture;
		snowProto.tileOffset = new Vector2(0f,0f);
		snowProto.tileSize = new Vector2(10f,10f);

		SplatPrototype[] prototypes = new SplatPrototype[2];
		prototypes[0] = groundProto;
		prototypes[1] = snowProto;
		terrainData.splatPrototypes = prototypes;

		_terrainTransform.localPosition = new Vector3( -0.5f*terrainData.size.x,0f,-0.5f*terrainData.size.z );

	}
开发者ID:ricardoAtXTeam,项目名称:ARClimberPrototypeAlpha,代码行数:51,代码来源:TerrainGenerator.cs


示例18: Construct

    public override void Construct(TerrainData data)
    {
        Vector3 position = transform.position;

        for (int y = 0; y < data.Height; y++)
        {
            for (int x = 0; x < data.Width; x++)
            {
                if (data.GetData(x, y) > 0)
                {
                    float worldX = x * m_blockSize + position.x;
                    float worldZ = y * m_blockSize + position.z;
                    float worldY = position.y;

                    GameObject newBlock = (GameObject) Instantiate(m_blocks[data.GetData(x, y) - 1], new Vector3(worldX, worldY, worldZ),
                        Quaternion.identity);
                }
            }
        }

        List<EmptyTerrainBlock> emptyTerrain = new List<EmptyTerrainBlock>(FindObjectsOfType<EmptyTerrainBlock>());

        int bodyBlock = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_bodyItems[Random.Range(0, m_bodyItems.Length)], emptyTerrain[bodyBlock].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(bodyBlock);

        int headBlock = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_headItems[Random.Range(0, m_headItems.Length)], emptyTerrain[headBlock].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(headBlock);

        int leftArm = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_armItems[Random.Range(0, m_armItems.Length)], emptyTerrain[leftArm].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(leftArm);

        int rightArm = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_armItems[Random.Range(0, m_armItems.Length)], emptyTerrain[rightArm].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(rightArm);

        int leftLeg = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_legItems[Random.Range(0, m_legItems.Length)], emptyTerrain[leftLeg].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(leftLeg);

        int rightLeg = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_legItems[Random.Range(0, m_legItems.Length)], emptyTerrain[rightLeg].transform.position + Vector3.up * m_blockSize * 0.5f + Vector3.up * m_itemOffset, Quaternion.identity);
        emptyTerrain.RemoveAt(rightLeg);

        int startBlock = Random.Range(0, emptyTerrain.Count);
        Instantiate(m_startArea, emptyTerrain[bodyBlock].transform.position + Vector3.up * m_blockSize * 0.5f,
            Quaternion.identity);
        emptyTerrain.RemoveAt(startBlock);
    }
开发者ID:bpeake13,项目名称:GGJ2016,代码行数:51,代码来源:TestTerrain.cs


示例19: 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);
    }
开发者ID:matkal-2,项目名称:Unity-Projects,代码行数:26,代码来源:WorldMap.cs


示例20: Start

 void Start()
 {
     tData = myTerrain.terrainData;
     xResolution = tData.heightmapWidth;
     zResolution = tData.heightmapHeight;
     heights = tData.GetHeights(0, 0, xResolution, zResolution);
 }
开发者ID:andywatts,项目名称:UnityGod,代码行数:7,代码来源:plane.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# TerrainTile类代码示例发布时间:2022-05-24
下一篇:
C# Terrain类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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