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


C# Terrain类代码示例

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


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

示例1: GenerateHeights

    public void GenerateHeights(Terrain terrain, float tileSize)
    {
        float[,] heightsA = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
        float[,] heightsB = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
        float[,] heightsC = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
        float[,] heightsFinal = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];

        for (int i = 0; i < terrain.terrainData.heightmapWidth; i++) {

            for (int k = 0; k < terrain.terrainData.heightmapHeight; k++) {

                heightsA[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * (tileSize / 10), ((float)k / (float)terrain.terrainData.heightmapHeight) * (tileSize / 10));

                if (heightsA[i, k] > 0.5f) heightsA[i, k] = 1.0f;
                else heightsA[i, k] = 0.0f;

                heightsA[i, k] = heightsA[i, k];

                heightsB[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * (tileSize / 1), ((float)k / (float)terrain.terrainData.heightmapHeight) * (tileSize / 1));

                heightsB[i, k] = heightsB[i, k] / 15.0f;

                heightsC[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * (tileSize / 5), ((float)k / (float)terrain.terrainData.heightmapHeight) * (tileSize / 5));

                heightsC[i, k] = heightsC[i, k] / 3.0f;

                heightsFinal[i, k] = heightsA[i, k] + heightsB[i, k] + heightsC[i, k];
            }
        }

        terrain.terrainData.SetHeights(0, 0, heightsFinal);
    }
开发者ID:Antrum,项目名称:Unity,代码行数:32,代码来源:TerrainGenerator.cs

示例2: Update

	void Update()
	{
		terrain = GetComponent<Terrain>();
		tData = terrain ? terrain.terrainData : null;
		tMaterial = terrain ? terrain.materialTemplate : null;
		if (!terrain || !tData || !tMaterial)
			return;
		
		if(disableBasemap && !Application.isPlaying && GetComponent<Terrain>().basemapDistance != 1000000) // only reset on update in edit mode
			GetComponent<Terrain>().basemapDistance = 1000000;
		if (cutoutMode)
		{
			if (tMaterial.HasProperty("_CutoutModeHideAlpha") && tMaterial.GetFloat("_CutoutModeHideAlpha") != cutoutModeHideAlpha)
				tMaterial.SetFloat("_CutoutModeHideAlpha", cutoutModeHideAlpha);
		}
		else
			if (tMaterial.HasProperty("_CutoutModeHideAlpha") && tMaterial.GetFloat("_CutoutModeHideAlpha") != -1)
				tMaterial.SetFloat("_CutoutModeHideAlpha", -1);

		if (!Application.isPlaying)
			ApplyTransparencyMap();
		else
			if (!transparencyMap && autoUpdateTransparencyMap)
			{
				UpdateTransparencyMap();
				ApplyTransparencyMap();
			}
			else
				ApplyTransparencyMap();
	}
开发者ID:theomission,项目名称:ozUnity,代码行数:30,代码来源:TerrainTransparency.cs

示例3: AsATerrainIShouldReceiveTheUpperBoundaryValuesAtInitialization

        public void AsATerrainIShouldReceiveTheUpperBoundaryValuesAtInitialization()
        {
            var terrain = new Terrain(new Coordinate("5 5"));

            Assert.AreEqual(5, terrain.UpperBoundary.X);
            Assert.AreEqual(5, terrain.UpperBoundary.Y);
        }
开发者ID:marcellalves,项目名称:marsrover,代码行数:7,代码来源:TerrainTest.cs

示例4: Explore

 /// <summary>
 /// explores the terrain
 /// </summary>
 public void Explore(Terrain terrain, IActor actor)
 {
     this.terrain = terrain;
     //the Explore starts from the start location in the terrain
     Explore(terrain.StartLocation, actor);
     Console.WriteLine("**** There are no more Exits ************");
 }
开发者ID:akrem1st,项目名称:Assignment2d,代码行数:10,代码来源:TerrainAutoExploration.cs

示例5: Start

    // Use this for initialization
    void Start()
    {
        // get terrain and size of terrain
        terrain = (Terrain)gameObject.GetComponent ("Terrain");
        //Vector3 tSize = terrain.terrainData.size;
        //Debug.Log (tSize);

        // set perlin noise origin coordinates
        float xOrg = Random.Range (0, .1f);
        float yOrg = Random.Range (0, .1f);

        // get heightmap
        float[,] heightmap = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];

        // fill array with perlin noise values
        for(int i=0;i<heightmap.GetLength(0);i++){
            for(int j=0;j<heightmap.GetLength(1);j++){
                float xCoord = xOrg + (float)i / ((float)heightmap.GetLength(0)/5);
                float yCoord = yOrg + (float)j / ((float)heightmap.GetLength(1)/5);
                heightmap[i,j] = Mathf.PerlinNoise(xCoord, yCoord);
            }
        }

        // reattatch array to terrain
        terrain.terrainData.SetHeights(0,0,heightmap);
    }
开发者ID:blackbret94,项目名称:ISProceduralGenerationGraphics,代码行数:27,代码来源:PerlinGenerator.cs

示例6: Main

 static void Main(string[] args)
 {
     Console.WriteLine("ENTER: 1 -> AutoPlayer; 2-> InteractivePlayer; 3->InteractiveWithMonters; 0->exit");
     Terrain terrain = new Terrain();
     IActor James;
     switch (Console.ReadLine())
     {
         case "0":
             Environment.Exit(1);
             break;
         case "1":
             James = new Actor();
             James.Name = "James";
             terrain.ConstructAndStartGame(James, new PlayerAutoExploreStrategy(), @"ConfigurationFiles\TerrainGraph.xml");
             break;
         case "2":
             James = new Player();
             James.ConstuctActor(@"ConfigurationFiles\PlayerConfiguration.xml");
             terrain.ConstructAndStartGame(James, new InteractiveStrategy(), @"ConfigurationFiles\InteractiveTerrainGraph.xml");
             break;
         case "3":
             James = new Player();
             James.ConstuctActor(@"ConfigurationFiles\PlayerConfiguration.xml");
             terrain.ConstructAndStartGame(James, new MultiCreatureAndExploreStrategy(new InteractiveStrategy()), @"ConfigurationFiles\MultiCreaturesTerrain.xml");
             Console.WriteLine("With Monsters");
             break;
         default:
             Console.WriteLine("Not valid choise. To Start again press 1 and then enter");
             if (Console.ReadLine() == "1")
                 Main(args);
             break;
     }
     Console.ReadKey();
 }
开发者ID:akrem1st,项目名称:Assignment2d,代码行数:34,代码来源:Program.cs

示例7: GamePlay

        public GamePlay(ContentManager contentManager)
        {
            //cManager.RootDirectory = "Content";
            //Console.WriteLine("Content Manager root directory: "+cManager.RootDirectory.ToString());
            //paddle = cManager.Load<Texture2D>(cManager.RootDirectory+"/GameAssets/breakout_paddle");
            //entityList = new List<Entities.BaseEntity>();

            currentKeyboardState = Keyboard.GetState();
            previousKeyboardState = currentKeyboardState;

            currentMouseState = Mouse.GetState();
            previousMouseState = Mouse.GetState();

            RoughnessPosition = new Vector2();
            RoughnessPosition.X = 100;
            RoughnessPosition.Y = 20;

            WaterTexture = contentManager.Load<Texture2D>("res/art/terrain/water_block");
            GrassTexture = contentManager.Load<Texture2D>("res/art/terrain/grass_block");
            MountainTexture = contentManager.Load<Texture2D>("res/art/terrain/mountain_block");
            kootenayFont = contentManager.Load<SpriteFont>("res/fonts/kootenay");

            _terrain = new Terrain("res/art/terrain/grass_block", _boxWidth, _boxHeight,
                Game1._DEFAULT_SCREEN_WIDTH, Game1._DEFAULT_SCREEN_HEIGHT, GrassTexture, WaterTexture, MountainTexture);
            _terrain.GenerateNewMap();

            _unitMap = new Unit[_terrain.ArrayWidth, _terrain.ArrayHeight];
            GenerateNewUnitMap();

            LoadContent(contentManager);
        }
开发者ID:il-domche,项目名称:BoxGame,代码行数:31,代码来源:GamePlay.cs

示例8: SetTextureOnTerrain

    public void SetTextureOnTerrain(Terrain terrain)
    {
        SplatPrototype[] va_sp = new SplatPrototype[2];

        va_sp[0] = new SplatPrototype();
        va_sp[0].texture = (Texture2D)Resources.Load("MyTextures/"+FirstTexture);
        va_sp[1] = new SplatPrototype();
        va_sp[1].texture = (Texture2D)Resources.Load("MyTextures/"+SecondTexture);
        terrain.terrainData.splatPrototypes = va_sp;
        int v_td_alphaMapResolution = terrain.terrainData.alphamapResolution;

        float[, ,] va_alphamaps = new float[v_td_alphaMapResolution, v_td_alphaMapResolution, va_sp.Length];
        va_alphamaps = terrain.terrainData.GetAlphamaps(0, 0, v_td_alphaMapResolution, v_td_alphaMapResolution);

        for (int ti = 0; ti < v_td_alphaMapResolution; ti++) {
            for (int tj = 0; tj < v_td_alphaMapResolution; tj++) {
                float y_01 = (float)tj/(float)terrain.terrainData.alphamapHeight;
                float x_01 = (float)ti/(float)terrain.terrainData.alphamapWidth;
                float height = terrain.terrainData.GetHeight(Mathf.RoundToInt(y_01 * terrain.terrainData.heightmapHeight),Mathf.RoundToInt(x_01 * terrain.terrainData.heightmapWidth) );
                for (int v_tex = 0; v_tex < va_sp.Length; v_tex++) {
                    if(height>HeightSeperation)
                        va_alphamaps[ti,tj,v_tex] = Random.Range(0.0f, 1);
                }
            }
        }
        terrain.terrainData.SetAlphamaps(0, 0, va_alphamaps);
    }
开发者ID:RCARL,项目名称:CS380Unity,代码行数:27,代码来源:Textures.cs

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

示例10: Start

    public void Start()
    {
        terr = Terrain.activeTerrain;

        //get position on terrain
        Vector3 pos = GetRelativeTerrainPositionFromPos(this.transform.position, terr, terr.terrainData.heightmapWidth, terr.terrainData.heightmapHeight);

        //get the heights at this position
        float[,] heights = Terrain.activeTerrain.terrainData.GetHeights((int)pos.x - (int)(GetComponent<BoxCollider>().bounds.size.x),
                                                                            (int)pos.z - (int)(GetComponent<BoxCollider>().bounds.size.z),
                                                                            (int)GetComponent<BoxCollider>().bounds.size.x + 2,
                                                                            (int)GetComponent<BoxCollider>().bounds.size.z + 2);

        //Debug.Log ("x: " + ((int)pos.x - (int)(GetComponent<BoxCollider> ().bounds.size.x)) + " \nz:" + ((int)pos.z - (int)(GetComponent<BoxCollider> ().bounds.size.z)));
        //Debug.Log ("x1:" + ( (int)GetComponent<BoxCollider>().bounds.size.x + 2)  + " \nz2:" + ((int)GetComponent<BoxCollider>().bounds.size.z + 2));
        //Debug.Log ("heights size: " + heights.Length);

        //decrease the terrain height of where the object is by the height of the object
           // Debug.Log("Size: " + this.GetComponent<BoxCollider>().bounds.size.x);
        for (int x = 0; x < heights.GetLength(1); ++x)
        {
            for (int y = 0; y < heights.GetLength(0); ++y)
            {
                //Debug.Log("Pos: " + x + " " + y + "\nheight before:"+heights[x,y]);
                heights[x, y] -= GetComponent<BoxCollider>().bounds.size.y + 100;
                //Debug.Log("height after:"+heights[x,y]);
            }
        }

        terr.terrainData.SetHeights((int)pos.x - (int)GetComponent<BoxCollider>().bounds.size.x / 2 , (int)(pos.z) - (int)(GetComponent<BoxCollider>().bounds.size.z / 2), heights);
    }
开发者ID:jmbooth,项目名称:Dungeon-God,代码行数:31,代码来源:terrainDeform.cs

示例11: TerrainInfo

 TerrainInfo(Terrain terrain)
 {
     Terrain = terrain;
     Rectangle = new RectangleD((int)Terrain % 4 / 4.0 + 0.0002,
                                (int)Terrain / 4 / 4.0 + 0.0002,
                                1 / 4.0 - 0.0004, 1 / 4.0 - 0.0004);
 }
开发者ID:eszanto8,项目名称:Cubecraft,代码行数:7,代码来源:Terrain.cs

示例12: Initialize

        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            terrain = entryA as Terrain;
            convex = entryB as ConvexCollidable;

            if (terrain == null || convex == null)
            {
                terrain = entryB as Terrain;
                convex = entryA as ConvexCollidable;

                if (terrain == null || convex == null)
                    throw new Exception("Inappropriate types used to initialize pair.");
            }

            //Contact normal goes from A to B.
            broadPhaseOverlap.entryA = convex;
            broadPhaseOverlap.entryB = terrain;

            UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, terrain.material);

            base.Initialize(entryA, entryB);




        }
开发者ID:rc183,项目名称:igf,代码行数:32,代码来源:TerrainPairHandler.cs

示例13: Start

    // Use this for initialization
    void Start()
    {
        R = Instantiate(MainTerrain) as Terrain;
        R.transform.position = new Vector3(MainTerrain.terrainData.size.x,0,0);
        L = Instantiate(MainTerrain) as Terrain;
        L.transform.position = new Vector3(-MainTerrain.terrainData.size.x,0,0);
        T = Instantiate(MainTerrain) as Terrain;
        T.transform.position = new Vector3(0,0,MainTerrain.terrainData.size.z);
        B = Instantiate(MainTerrain) as Terrain;
        B.transform.position = new Vector3(0,0,-MainTerrain.terrainData.size.z);

        TR = Instantiate(MainTerrain) as Terrain;
        TR.transform.position = new Vector3(MainTerrain.terrainData.size.x,0,MainTerrain.terrainData.size.z);
        BR = Instantiate(MainTerrain) as Terrain;
        BR.transform.position = new Vector3(MainTerrain.terrainData.size.x,0,-MainTerrain.terrainData.size.z);
        TL = Instantiate(MainTerrain) as Terrain;
        TL.transform.position = new Vector3(-MainTerrain.terrainData.size.x,0,MainTerrain.terrainData.size.z);
        BL = Instantiate(MainTerrain) as Terrain;
        BL.transform.position = new Vector3(-MainTerrain.terrainData.size.x,0,-MainTerrain.terrainData.size.z);

        TL.SetNeighbors(null,null,T,L);
        T.SetNeighbors(TL,null,TR,MainTerrain);
        TR.SetNeighbors(T,null,null,R);
        L.SetNeighbors(null,TL,MainTerrain,BL);
        MainTerrain.SetNeighbors(L,T,R,B);
        R.SetNeighbors(MainTerrain,TR,null,BR);
        BL.SetNeighbors(null,L,B,null);
        B.SetNeighbors(BL,MainTerrain,BR,null);
        BR.SetNeighbors(B,R,null,null);
    }
开发者ID:TheCraiggers,项目名称:MoonKrieg,代码行数:31,代码来源:DupeTerrain.cs

示例14: Main

        static void Main(string[] args)
        {
            /* Player Auto explor

            string str = "satish";
            Convert.ToInt32(str[1]);
            Terrain terrain = new Terrain();
            terrain.PrepareTerrainFromXml(@"ConfigurationFiles\TerrainGraph.xml");
            var player = new Player() { Name = "Akrem" };
            terrain.Subscribe(TripRecorder.Instance);

            var terrainExplore = new TerrainAutoExploration(player, terrain);
            //Call the automated Exploration method
            terrainExplore.Explore();
            */

            // this is a test
            Terrain terrain = new Terrain();
            terrain.PrepareInteractiveTerrainFromXml(@"ConfigurationFiles\InteractiveTerrainGraph.xml");

            Player player = new Player();
            player.PreparePlayerFromXml(@"ConfigurationFiles\PlayerConfiguration.xml");

            terrain.InteractiveExplore(player);
        }
开发者ID:akrem1st,项目名称:Assignment2c-git,代码行数:25,代码来源:Program.cs

示例15: Start

    void Start()
    {
        terr = (Terrain) GetComponent(typeof(Terrain));
        terr.name = "Terrain";
        Tw = terr.terrainData.heightmapWidth;
        Th = terr.terrainData.heightmapHeight;
        heightMapBackup = terr.terrainData.GetHeights(0, 0, Tw, Th);
        initHeightMap = terr.terrainData.GetHeights(0, 0, Tw, Th);

        for (int i=0; i<Tw; i++)
        {
            for (int j=0; j<Th; j++)
            {
                initHeightMap[i,j] = 0;//desiredHeight;//desiredHeight;
            }
        }

        Debug.Log("START TERRAIN");
        terr.terrainData.SetHeights(0,0,initHeightMap);

        Debug.Log(terr.detailObjectDistance.ToString());
        Terrain.activeTerrain.detailObjectDistance = 10000;
        Terrain.activeTerrain.basemapDistance = 1000;
        //terr.detailObjectDistance = 1000;
        instance = this;
        //generateTerrain.instance.UpdateTerrainHeight(0, 0, 8.0f);
        //generateTerrain.instance.UpdateTerrainHeight(128, 128, 8.0f);
    }
开发者ID:SLIPD,项目名称:PC,代码行数:28,代码来源:generateTerrain.cs


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