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


C# Terrain.GetPosition方法代码示例

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


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

示例1: OnTriggerEnter

    void OnTriggerEnter(Collider col)
    {
        if(col.gameObject.tag == "Terrain"){

            prevTerrain = Instantiate(TerrainPieces[(int)Random.Range(0, TerrainPieces.Length)], new Vector3(0, 0, prevTerrain.GetPosition().z + prevTerrain.terrainData.size.z), Quaternion.identity)as Terrain;
            GameObject temp = Instantiate(TerrainObjects, new Vector3(0, 0, prevTerrain.GetPosition().z), Quaternion.identity)as GameObject;

        }
    }
开发者ID:Tarwine,项目名称:SquireJam2014,代码行数:9,代码来源:TerrainGenerator.cs

示例2: 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

示例3: 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

示例4: SnapBig

	static void SnapBig(Terrain t, Camera cam, int size, int wCount, string path)
	{

		float nearClip = 0.3f;
		float camSize = t.terrainData.size.x /2;
		Vector3 offset = t.GetPosition() + new Vector3(camSize, 0, camSize) + (t.terrainData.size.y  + nearClip) * Vector3.up;
		cam.nearClipPlane = nearClip;
		cam.farClipPlane = t.terrainData.size.y + nearClip * 2;
		cam.orthographicSize = camSize;
		cam.transform.position = offset;
		cam.depth = int.MaxValue;
		

		cam.targetTexture = new RenderTexture(512, 512, 32, RenderTextureFormat.ARGB32);
		RenderTexture.active = cam.targetTexture;

		string filePath = System.IO.Path.Combine(path, "snapMap.png");
		SnapShot(cam, filePath);
		Debug.Log("Snap done: @ " + filePath);
	}
开发者ID:fengqk,项目名称:Art,代码行数:20,代码来源:SnapMap.cs

示例5: Grid

        public Grid(Terrain terrain, float sample, float heightCost)
        {
            _terrain = terrain;

            _worldPosition = terrain.GetPosition();
            var width = (int)terrain.terrainData.size.x;
            var height = (int)terrain.terrainData.size.z;

            SampledWidth = (int)Mathf.Ceil(width / sample);
            SampledHeight = (int)Mathf.Ceil(height / sample);
            _sample = sample;
            _heightCost = heightCost;
            InternalGrid = new Node[SampledWidth, SampledHeight];
            InternalGridWithUnwalkable = new Node[SampledWidth, SampledHeight];
            //Build the Grid [width,height] --> O(n^2)
            InitGrid();
            InitGridWithUnWalkable();

            //Initialize the edges/neighboots --> O(n^2)
            InitEdges();
            InitEdgesWithUnWalkable();
        }
开发者ID:vladdie,项目名称:Autonomous-Agents,代码行数:22,代码来源:Grid.cs

示例6: SampleHeightInfos

	void SampleHeightInfos(Terrain terrain, int widthGridCount, int lengthGridCount)
	{
		Vector3 terrainPos = terrain.GetPosition();
		terrain.transform.position = Vector3.zero;
		GameObject meshObj;
		MeshCollider cld;
		GenMeshColliderFromNavMesh(out meshObj, out cld);

		frees = new bool[widthGridCount][];
		for (int i = 0; i < widthGridCount; i++)
		{
			frees[i] = new bool[lengthGridCount];
		}

		xCount = widthGridCount + 1;
		zCount = lengthGridCount + 1;

		hitPositions = new Vector3[xCount][];
		for (int i = 0; i < xCount; i++)
		{
			hitPositions[i] = new Vector3[zCount];
		}

		__notHitCount = 0;

		float stepX = terrain.terrainData.size.x / widthGridCount;
		float stepZ = terrain.terrainData.size.z / lengthGridCount;
		centerOffset = new Vector3(stepX * 0.5f, 0, stepZ * 0.5f);

		float y = terrain.terrainData.size.y + 1;
		float distance = y + 2;
		// heights
		for (int z = 0; z < zCount; z++)
		{
			for (int x = 0; x < xCount; x++)
			{
				Vector3 sourcePoint = new Vector3(x * stepX, y, z * stepZ);
				bool hit = SampleHeight(sourcePoint, distance * 2, out hitPositions[x][z], 1 << layerID);
				if (!hit)
				{
					__notHitCount++;
				}
				hitPositions[x][z] += terrainPos;
			}
		}
		centerPositions = CenterPositionsFromHitPositions(hitPositions);
		// reachable
		for (int z = 0; z < lengthGridCount; z++)
		{
			for (int x = 0; x < widthGridCount; x++)
			{
				Vector3 sourcePoint = new Vector3(x * stepX, y, z * stepZ) + centerOffset;
				Vector3 tempHitPos;
				bool hit = SampleHeight(sourcePoint, distance * 2, out tempHitPos, 1 << layerID);
				Ray ray = new Ray(sourcePoint, Vector3.down);
				RaycastHit raycastHit;
				frees[x][z] = cld.Raycast(ray, out raycastHit, distance);
			}
		}
		////

		GameObject.DestroyImmediate(meshObj);
		terrain.transform.position = terrainPos;
	}
开发者ID:fengqk,项目名称:Art,代码行数:64,代码来源:SampleHeightAndReachable.cs

示例7: 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

示例8: SplitIt

    void SplitIt()
    {
        if ( Selection.activeGameObject == null )
        {
            Debug.LogWarning("No terrain was selected");
            return;
        }

        parentTerrain = Selection.activeGameObject.GetComponent(typeof(Terrain)) as Terrain;

        if ( parentTerrain == null )
        {
            Debug.LogWarning("Current selection is not a terrain");
            return;
        }

        //Split terrain
        for ( int i=0; i< terrainsCount; i++)
        {

            EditorUtility.DisplayProgressBar("Split terrain","Process " + i, (float) i / terrainsCount );

            TerrainData td = new TerrainData();
            GameObject tgo = Terrain.CreateTerrainGameObject( td );

            tgo.name = parentTerrain.name + " " + i;

            terrainData.Add( td );
            terrainGo.Add ( tgo );

            Terrain genTer = tgo.GetComponent(typeof(Terrain)) as Terrain;
            genTer.terrainData = td;

            AssetDatabase.CreateAsset(td, "Assets/" + genTer.name+ ".asset");

            // Assign splatmaps
            genTer.terrainData.splatPrototypes = parentTerrain.terrainData.splatPrototypes;

            // Assign detail prototypes
            genTer.terrainData.detailPrototypes = parentTerrain.terrainData.detailPrototypes;

            // Assign tree information
            genTer.terrainData.treePrototypes = parentTerrain.terrainData.treePrototypes;

            // Copy parent terrain propeties
            #region parent properties
            genTer.basemapDistance = parentTerrain.basemapDistance;
            genTer.castShadows = parentTerrain.castShadows;
            genTer.detailObjectDensity = parentTerrain.detailObjectDensity;
            genTer.detailObjectDistance = parentTerrain.detailObjectDistance;
            genTer.heightmapMaximumLOD = parentTerrain.heightmapMaximumLOD;
            genTer.heightmapPixelError = parentTerrain.heightmapPixelError;
            genTer.treeBillboardDistance = parentTerrain.treeBillboardDistance;
            genTer.treeCrossFadeLength = parentTerrain.treeCrossFadeLength;
            genTer.treeDistance = parentTerrain.treeDistance;
            genTer.treeMaximumFullLODCount = parentTerrain.treeMaximumFullLODCount;

            #endregion

            //Start processing it

            // Translate peace to position
            #region translate peace to right position

            Vector3 parentPosition = parentTerrain.GetPosition();

            int terraPeaces = (int) Mathf.Sqrt( terrainsCount );

            float spaceShiftX = parentTerrain.terrainData.size.z / terraPeaces;
            float spaceShiftY = parentTerrain.terrainData.size.x / terraPeaces;

            float xWShift = (i % terraPeaces ) * spaceShiftX;
            float zWShift = ( i / terraPeaces ) * spaceShiftY;

            tgo.transform.position = new Vector3( tgo.transform.position.x + zWShift,
                                                  tgo.transform.position.y,
                                                  tgo.transform.position.z + xWShift );

            // Shift last position
            tgo.transform.position = new Vector3( tgo.transform.position.x + parentPosition.x,
                                                  tgo.transform.position.y + parentPosition.y,
                                                  tgo.transform.position.z + parentPosition.z
                                                 );

            #endregion

            // Split height
            #region split height

            Debug.Log ( "Split height" );

            //Copy heightmap
            td.heightmapResolution = parentTerrain.terrainData.heightmapResolution /  terraPeaces;

            //Keep y same
            td.size = new Vector3( parentTerrain.terrainData.size.x / terraPeaces,
                                   parentTerrain.terrainData.size.y,
                                   parentTerrain.terrainData.size.z / terraPeaces
                                  );

//.........这里部分代码省略.........
开发者ID:cathoangludi,项目名称:TreadLightly,代码行数:101,代码来源:SplitTerrain.cs

示例9: SampleHeightInfos

	void SampleHeightInfos(Terrain terrain, int widthGridCount, int lengthGridCount)
	{
		Vector3 terrainPos = terrain.GetPosition();
		terrain.transform.position = Vector3.zero;
		GameObject meshObj;
		MeshCollider cld;
		GenMeshColliderFromNavMesh(out meshObj, out cld);

		frees = new bool[widthGridCount][];
		isWayPoints = new bool[widthGridCount][];
		for (int i = 0; i < widthGridCount; i++)
		{
			frees[i] = new bool[lengthGridCount];
			isWayPoints[i] = new bool[lengthGridCount];
		}

		xCount = widthGridCount + 1;
		zCount = lengthGridCount + 1;

		hitPositions = new Vector3[xCount][];
		for (int i = 0; i < xCount; i++)
		{
			hitPositions[i] = new Vector3[zCount];
		}

		__notHitCount = 0;

		float stepX = terrain.terrainData.size.x / widthGridCount;
		float stepZ = terrain.terrainData.size.z / lengthGridCount;
		centerOffset = new Vector3(stepX * 0.5f, 0, stepZ * 0.5f);

		float y = terrain.terrainData.size.y + 1;
		float distance = y + 2;
		// heights
		for (int z = 0; z < zCount; z++)
		{
			for (int x = 0; x < xCount; x++)
			{
				Vector3 sourcePoint = new Vector3(x * stepX, y, z * stepZ);
				bool hit = SampleHeight(sourcePoint, distance * 2, out hitPositions[x][z], 1 << layerID);
				if (!hit)
				{
					__notHitCount++;
				}
				hitPositions[x][z] += terrainPos;
			}
		}
		centerPositions = CenterPositionsFromHitPositions(hitPositions);
		// reachable
		/*
		for (int z = 0; z < lengthGridCount; z++)
		{
			for (int x = 0; x < widthGridCount; x++)
			{
				Vector3 sourcePoint = new Vector3(x * stepX, y, z * stepZ) + centerOffset;
				Vector3 tempHitPos;
				bool hit = SampleHeight(sourcePoint, distance * 2, out tempHitPos, 1 << layerID);
				Ray ray = new Ray(sourcePoint, Vector3.down);
				RaycastHit raycastHit;
				frees[x][z] = cld.Raycast(ray, out raycastHit, distance);
			}
		}
		 */
		////
		//// new 
		bool[][] hitNav = new bool[xCount][];
		bool[][] hitCld = new bool[xCount][];
		for (int i = 0; i < hitNav.Length; i++)
		{
			hitNav[i] = new bool[zCount];
			hitCld[i] = new bool[zCount];
		}
		for (int z = 0; z < zCount; z++)
		{
			for (int x = 0; x < xCount; x++)
			{
				Vector3 sourcePoint = new Vector3(x * stepX, y, z * stepZ);
				Vector3 tempHitPos;
				//hitNav[x][z] = SampleHeight(sourcePoint, distance * 2, out tempHitPos, 1 << layerID);
				hitCld[x][z] = SampleHeight(sourcePoint, distance * 2, out tempHitPos, 1 << colliderID);
				Ray ray = new Ray(sourcePoint, Vector3.down);
				RaycastHit raycastHit;
				hitNav[x][z] = cld.Raycast(ray, out raycastHit, distance);
			}
		}
		for (int z = 0; z < zCount - 1; z++)
		{
			for (int x = 0; x < xCount - 1; x++)
			{
				bool b0 = hitCld[x][z];
				bool b1 = hitCld[x + 1][z];
				bool b2 = hitCld[x + 1][z + 1];
				bool b3 = hitCld[x][z + 1];
				frees[x][z] = !(b0 && b1 && b2 && b3);

				bool f0 = hitNav[x][z];
				bool f1 = hitNav[x + 1][z];
				bool f2 = hitNav[x + 1][z + 1];
				bool f3 = hitNav[x][z + 1];
				if (frees[x][z])
//.........这里部分代码省略.........
开发者ID:fengqk,项目名称:Art,代码行数:101,代码来源:SampleHeightAndReachableV2.cs


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