当前位置: 首页>>代码示例>>C#>>正文


C# TerrainData类代码示例

本文整理汇总了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);*/
    }
开发者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: 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

示例15: 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;未经允许,请勿转载。