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


C# Terrain.SampleHeight方法代码示例

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


在下文中一共展示了Terrain.SampleHeight方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartBuilding

	public void StartBuilding(Player player) {
		owner = player;
		isBuilt = true;
		creationProgress = 0;
		spawnPoint = transform.position;
		while(this.GetComponent<Collider>().bounds.Contains (spawnPoint))
			spawnPoint += transform.forward;
		terrain = Terrain.activeTerrain;
		spawnPoint.y = terrain.SampleHeight(spawnPoint) + unit.GetComponent<Renderer>().bounds.size.y;
	}
开发者ID:ltasler,项目名称:Hello-Game,代码行数:10,代码来源:Building.cs

示例2: RandomPositionOnTerrain

    private Vector3 RandomPositionOnTerrain(Terrain terrain, int offset = 0)
    {
        var terrainPos = terrain.transform.position;
        var size = terrain.terrainData.size;

        var pos = Vector3.zero;
        pos.x = Random.Range(terrainPos.x + offset, terrainPos.x + size.x - offset);
        pos.z = Random.Range(terrainPos.z + offset, terrainPos.z + size.z - offset);

        pos.y = terrain.SampleHeight(pos);

        return pos;
    }
开发者ID:TobieD,项目名称:City-Generator,代码行数:13,代码来源:CharacterSpawner.cs

示例3: DrawBrush

        public void DrawBrush(Vector3 pos, float radius, Terrain terrain, Color color, float thickness=3f, int numCorners=32)
        {
            //incline is the height delta in one unit distance
            Handles.color = color;

            Vector3[] corners = new Vector3[numCorners+1];
            float step = 360f/numCorners;
            for (int i=0; i<=corners.Length-1; i++)
            {
            corners[i] = new Vector3( Mathf.Sin(step*i*Mathf.Deg2Rad), 0, Mathf.Cos(step*i*Mathf.Deg2Rad) ) * radius + pos;
            corners[i].y = terrain.SampleHeight(corners[i]);
            }
            Handles.DrawAAPolyLine(thickness, corners);
        }
开发者ID:fforres,项目名称:OculusRiftTesting,代码行数:14,代码来源:NoiseBrushEditor.cs

示例4: InitializePosition

    public Vector3 InitializePosition(Terrain terrain)
    {
        var terrainStartPosition = terrain.GetPosition ();
        var xPosition = (terrainStartPosition.x + terrain.terrainData.size.x) / 2.0f;
        var zPosition = (terrainStartPosition.z + terrain.terrainData.size.z) / 2.0f;

        Vector3 airplanePosition = new Vector3 ();
        airplanePosition.x = xPosition;
        airplanePosition.z = zPosition;
        airplanePosition.y = terrain.SampleHeight (airplanePosition) + StartHeightDistanceBetweenTerrainAdnAirplane;

        gameObject.transform.position = airplanePosition;

        return airplanePosition;
    }
开发者ID:Krzyrok,项目名称:Unity-FlightSimulatorWithTerrainGenerator,代码行数:15,代码来源:AirplaneController.cs

示例5: AddGrave

    public void AddGrave(int x, int y, Terrain terrain)
    {
        TerrainData data = terrain.terrainData;
        float xNormalized = x/(float)data.size.x;
        float yNormalized = x/(float)data.size.y;
        float scaleRatio = Random.Range(0.8f,1.2f);

        Vector3 spawnPos = Vector3.zero;
        spawnPos.x = x + terrain.GetPosition().x;
        spawnPos.z = y + terrain.GetPosition().z;
        spawnPos.y = terrain.SampleHeight(spawnPos)-0.1f;

        GameObject go = GameObject.Instantiate(gravePrefabs[Random.Range(0,gravePrefabs.Length)],spawnPos,Quaternion.identity) as GameObject;
        go.transform.localScale = Vector3.one * scaleRatio;
        go.transform.parent = terrain.transform;
        RaycastHit hitInfo;
        if(Physics.Linecast(go.transform.position + Vector3.up,go.transform.position - Vector3.up * 50.0f,out hitInfo)){
            go.transform.up = hitInfo.normal;
        }

        go.transform.RotateAround(go.transform.up,Random.Range(0.0f,360.0f));
    }
开发者ID:zipOrg,项目名称:CemeteryShoeter,代码行数:22,代码来源:Generator.cs

示例6: SetWaterYCoordinate

    /// <summary>
    /// Create heights and assign it to the passed terrain
    /// </summary>
    /// <param name="terrain">Terrain</param>
    public void SetWaterYCoordinate(Terrain terrain)
    {
        Vector3 lowestPoint = new Vector3(100f, 100f, 100f);

        for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
        {
            for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
            {
                Vector3 worldPoint = terrain.transform.TransformPoint(new Vector3(i, 0f, k));
                float height = terrain.SampleHeight(worldPoint);
                if (height < lowestPoint.z)
                {
                    lowestPoint = new Vector3(i, k, height);
                }
            }

        }
        //Debug.Log("Lowest point:" + lowestPoint.x + ", " + lowestPoint.y + ", " + lowestPoint.z);

        // Set the water at this plus the water depth
        Vector3 waterPosition = Water.transform.position;
        waterPosition.y = lowestPoint.z + MaxWaterHeight;
        Water.transform.position = waterPosition;
    }
开发者ID:admiralronton,项目名称:UnityCarTechDemo,代码行数:28,代码来源:WaterPlacer.cs

示例7: TriangulateSurface

        private static void TriangulateSurface(Terrain terrain
            , Vector3 origin
            , Vector3 scale
            , int xCount
            , int zCount
            , float yOffset
            , TriangleMesh buffer)
        {

            // Create the vertices by sampling the terrain.
            for (int ix = 0; ix < xCount; ix++)
            {
                float x = origin.x + ix * scale.x;
                for (int iz = 0; iz < zCount; iz++)
                {
                    float z = origin.z + iz * scale.z;
                    Vector3 pos = new Vector3(x, origin.y, z);
                    pos.y += terrain.SampleHeight(pos) + yOffset;
                    buffer.verts[buffer.vertCount] = pos;
                    buffer.vertCount++;
                }
            }

            // Triangulate surface sample points.
            for (int ix = 0; ix < xCount - 1; ix++)
            {
                for (int iz = 0; iz < zCount - 1; iz++)
                {
                    int i = iz + (ix * zCount);
                    int irow = i + zCount;

                    buffer.tris[buffer.triCount * 3 + 0] = i;
                    buffer.tris[buffer.triCount * 3 + 1] = irow + 1;
                    buffer.tris[buffer.triCount * 3 + 2] = irow;
                    buffer.triCount++;

                    buffer.tris[buffer.triCount * 3 + 0] = i;
                    buffer.tris[buffer.triCount * 3 + 1] = i + 1;
                    buffer.tris[buffer.triCount * 3 + 2] = irow + 1;
                    buffer.triCount++;
                }
            }
        }
开发者ID:BibleUs,项目名称:critterai,代码行数:43,代码来源:TerrainUtil.cs

示例8: CalculateHeight

	private bool CalculateHeight(Terrain ter, int x, int y, DetailSettings ds)
	{
		if (ds.MinimumHeight == 0 && ds.MaximumHeight == 0)
			return true;
		
		float xDim = x * xUnit;
		float yDim = y * yUnit;
		Vector3 realPosition = new Vector3(yDim, 0, xDim);
		float positionY = ter.SampleHeight(realPosition);
		if (positionY < ds.MinimumHeight || positionY > ds.MaximumHeight)
		{
			return false;
		}
		return true;
	}
开发者ID:esmayl,项目名称:De-Zuidlanden-Stage-project,代码行数:15,代码来源:BasicTerrainMapper.cs

示例9: SetSceneVerts

        public void SetSceneVerts(Terrain t)
        {
            if (SceneVerts == null) SceneVerts = new Vector3[4];
            Vector3 scale = new Vector3(width, 1, depth);

            float tl = t.SampleHeight(center + new Vector3(-width / 2.0f, 0, depth / 2.0f));
            float tr = t.SampleHeight(center + new Vector3(width / 2.0f, 0, depth / 2.0f));
            float bl = t.SampleHeight(center + new Vector3(-width / 2.0f, 0, -depth / 2.0f));
            float br = t.SampleHeight(center + new Vector3(width / 2.0f, 0, -depth / 2.0f));

            SceneVerts[0] = center + new Vector3(-width / 2.0f, bl - center.y, -depth / 2.0f);
            SceneVerts[1] = center + new Vector3(-width / 2.0f, tl - center.y, depth / 2.0f);
            SceneVerts[2] = center + new Vector3(width / 2.0f, tr - center.y, depth / 2.0f);
            SceneVerts[3] = center + new Vector3(width / 2.0f, br - center.y, -depth / 2.0f);
        }
开发者ID:kteynorprivate,项目名称:TeykeToolkit,代码行数:15,代码来源:GridmapCell.cs

示例10: CellIsSmooth

        private bool CellIsSmooth(GridmapCell c, Terrain t)
        {
            // grab 4-corners + center heights
            float ch = t.SampleHeight(c.center);
            float tl = t.SampleHeight(c.center + new Vector3(-cellWidth / 2.0f, 0, cellDepth / 2.0f));
            float tr = t.SampleHeight(c.center + new Vector3(cellWidth / 2.0f, 0, cellDepth / 2.0f));
            float bl = t.SampleHeight(c.center + new Vector3(-cellWidth / 2.0f, 0, -cellDepth / 2.0f));
            float br = t.SampleHeight(c.center + new Vector3(cellWidth / 2.0f, 0, -cellDepth / 2.0f));

            // check if center diff is too big:
            if (Mathf.Abs(ch - tl) > cliffHeight ||
                Mathf.Abs(ch - tr) > cliffHeight ||
                Mathf.Abs(ch - bl) > cliffHeight ||
                Mathf.Abs(ch - br) > cliffHeight)
                return false;

            // check if top-left diff is too big:
            if (Mathf.Abs(tl - tr) > cliffHeight ||
                Mathf.Abs(tl - bl) > cliffHeight)
                return false;

            // check if bot-right diff is too big:
            if (Mathf.Abs(br - tr) > cliffHeight ||
                Mathf.Abs(br - bl) > cliffHeight)
                return false;

            return true;
        }
开发者ID:kteynorprivate,项目名称:TeykeToolkit,代码行数:28,代码来源:Gridmap.cs

示例11: SpawnGameOverSwitch

 public void SpawnGameOverSwitch(Terrain terrain)
 {
     Vector3 spawnPos = terrain.GetPosition() + new Vector3(128.0f, 0.0f, 256.0f);
     GameObject go = GameObject.Instantiate(gameOverSwitchPrefab,spawnPos,Quaternion.Euler(new Vector3(0.0f,0.0f,180.0f))) as GameObject;
     UserInterface.SetText2("Find the light, and be free...");
     Vector3 pos = go.transform.position;
     pos.y = terrain.SampleHeight(go.transform.position) + 0.8f;
     go.transform.position = pos;
 }
开发者ID:zipOrg,项目名称:CemeteryShoeter,代码行数:9,代码来源:Generator.cs


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