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


C# Chunk类代码示例

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


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

示例1: GenerateChunk

        public IChunk[] GenerateChunk(IEnumerable<IBlockDefinition> blockDefinitions, IPlanet planet, Index2 index)
        {
            IBlockDefinition sandDefinition = blockDefinitions.FirstOrDefault(d => typeof(SandBlockDefinition) == d.GetType());
            ushort sandIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), sandDefinition) + 1);

            IChunk[] result = new IChunk[planet.Size.Z];

            for (int layer = 0; layer < planet.Size.Z; layer++)
                result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet.Id);

            int part = (planet.Size.Z * Chunk.CHUNKSIZE_Z) / 4;

            for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++)
            {
                float heightY = (float)Math.Sin((float)(y * Math.PI) / 15f);
                for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
                {
                    float heightX = (float)Math.Sin((float)(x * Math.PI) / 18f);

                    float height = ((heightX + heightY + 2) / 4) * (2 * part);
                    for (int z = 0; z < planet.Size.Z * Chunk.CHUNKSIZE_Z; z++)
                    {
                        if (z < (int)(height + part))
                        {
                            int block = z % (Chunk.CHUNKSIZE_Z);
                            int layer = (int)(z / Chunk.CHUNKSIZE_Z);
                            result[layer].SetBlock(x, y, block, sandIndex);
                        }
                    }
                }
            }

            return result;
        }
开发者ID:RapidHelmus,项目名称:octoawesome,代码行数:34,代码来源:DebugMapGenerator.cs

示例2: Load

    public static bool Load(Chunk chunk)
    {

        string saveFile = SaveLocation(chunk.world.worldName);
        saveFile += FileName(chunk.pos);

        if (!File.Exists(saveFile))
            return false;
        try
        {

            IFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(saveFile, FileMode.Open);

            Save save = (Save)formatter.Deserialize(stream);

            //Once the blocks in the save are added they're marked as unmodified so
            //as not to trigger a new save on unload unless new blocks are added.
            for (int i =0; i< save.blocks.Length; i++)
            {
                Block placeBlock = save.blocks[i];
                placeBlock.modified = false;
                chunk.SetBlock(save.positions[i], placeBlock, false);
            }

            stream.Close();
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }


        return true;
    }
开发者ID:li5414,项目名称:Voxelmetric,代码行数:35,代码来源:Serialization.cs

示例3: ChunkDrawData

 public ChunkDrawData(List<Vector3> vertexlist, List<int> trianglelist, List<Vector2> uvlist, Chunk chnk)
 {
     vertexList = vertexlist;
     triangleList = trianglelist;
     UVList = uvlist;
     chunk = chnk;
 }
开发者ID:AlexanderMazaletskiy,项目名称:YetAnotherMinecraftClone,代码行数:7,代码来源:ChunkDrawData.cs

示例4: Decorate

    public virtual void Decorate(Chunk chunk)
    {
        if (Decorations != null && Decorations.Length > 0)
        {
            for (int i = 0; i < Decorations.Length; i++)
            {
                for (int j = 0; j < Decorationscount[i]; j++)
                {
                    int x = DataBaseHandler.DataBase.random.Next(0, DataBaseHandler.ChunkSize);
                    int y = DataBaseHandler.DataBase.random.Next(0, DataBaseHandler.ChunkSize);

                    if (chunk.biomes[Mathf.RoundToInt((((float)DataBaseHandler.BiomeMapSize - (float)1) / (float)DataBaseHandler.ChunkSize) * y), Mathf.RoundToInt((((float)DataBaseHandler.BiomeMapSize - (float)1) / (float)DataBaseHandler.ChunkSize) * x)] == Type)
                    {
                        RaycastHit hit;
                        Physics.Raycast(
                            new Vector3(chunk.transform.position.x + x, -1, chunk.transform.position.z + y), Vector3.up,
                            out hit, (float)DataBaseHandler.ChunkSize * 2.5f, 1);
                        GameObject go = (GameObject)GameObject.Instantiate(Decorations[i]);
                        go.transform.parent = chunk.transform;
                        go.transform.localPosition = new Vector3(x, hit.point.y, y);
                        Vector3 rot = Random.rotation.eulerAngles;
                        go.transform.eulerAngles = new Vector3(0, DataBaseHandler.DataBase.random.Next(0, 360), 0);
                        go.AddComponent<TreeHandler>();
                    }
                }
            }
        }
    }
开发者ID:hybrid1969,项目名称:UCN-Sem5-2014,代码行数:28,代码来源:Biome.cs

示例5: GenerateBlocks

        protected override void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                    if (chunk.LowestEmptyBlockOffset > y) chunk.LowestEmptyBlockOffset = (byte)y;
                }
                else if (y > rockHeight) // dirt
                {
                    var valleyNoise = this.GenerateValleyNoise(worldPositionX, worldPositionZ, y);
                    BlockStorage.Blocks[offset + y] = new Block(valleyNoise > 0.2f ? BlockType.None : BlockType.Dirt);
                    if (y > chunk.HighestSolidBlockOffset) chunk.HighestSolidBlockOffset = (byte)y;
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                    if (y > chunk.HighestSolidBlockOffset) chunk.HighestSolidBlockOffset = (byte)y;
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX + this.Seed, worldPositionZ);
        }
开发者ID:landongn,项目名称:voxeliq,代码行数:30,代码来源:ValleyTerrain.cs

示例6: TileMap

        public TileMap(int width, int height, Texture texture)
        {
            Width = width;
            Height = height;

            var lastTile = texture == null ? ushort.MaxValue : (ushort)((texture.Size.X / GameOptions.TileSize) * (texture.Size.Y / GameOptions.TileSize) - 1);

            tiles = new Tile[width, height];

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    tiles[x, y].Index = lastTile;
                    tiles[x, y].Solid = false;
                }
            }

            var chunkWidth = (width / GameOptions.TileChunkSize) + 1;
            var chunkHeight = (height / GameOptions.TileChunkSize) + 1;

            chunks = new Chunk[chunkWidth, chunkHeight];

            for (var y = 0; y < chunkHeight; y++)
            {
                for (var x = 0; x < chunkWidth; x++)
                {
                    chunks[x, y] = new Chunk(x, y, tiles, texture);
                }
            }
        }
开发者ID:DatZach,项目名称:HumanityAgainstCards,代码行数:31,代码来源:TileMap.cs

示例7: GenerateChunk

 public Chunk GenerateChunk(Vector3 position)
 {
     var chunk = new Chunk(position);
     int y = 0;
     for (int i = 0; i < Layers.Count; i++)
     {
         int height = y + Layers[i].Height;
         while (y < height)
         {
             for (int x = 0; x < 16; x++)
             {
                 for (int z = 0; z < 16; z++)
                 {
                     chunk.SetBlock(new Vector3(x, y, z), Layers[i].Block);
                 }
             }
             y++;
         }
     }
     for (int i = 0; i < chunk.Biomes.Length; i++)
         chunk.Biomes[i] = (byte)Biome;
     // TESTING
     // Dig out a little to test sky light
     for (y = 3; y > 0; y--)
         chunk.SetBlock(new Vector3(8, y, 8), new AirBlock());
     for (int x = -5; x < 5; x++)
         for (int z = -5; z < 5; z++)
             for (y = 2; y > 0; y--)
                 chunk.SetBlock(new Vector3(8 + x, y, 8 + z), new AirBlock());
     // /TESTING
     return chunk;
 }
开发者ID:cpancake,项目名称:Craft.Net,代码行数:32,代码来源:FlatlandGenerator.cs

示例8: ApplyChunkSettings

	public void ApplyChunkSettings(Chunk chunk, CubedObjectBehaviour parent) {
		this.chunk = chunk;
		renderer.materials = new Material[] { chunk.blockMaterial };
		
		var mesh = new Mesh();
		mesh.Clear();
	    mesh.vertices = chunk.meshData.RenderableVertices.ToArray();
	    mesh.triangles = chunk.meshData.RenderableTriangles.ToArray();
	    mesh.uv = chunk.meshData.RenderableUvs.ToArray();
	    mesh.RecalculateNormals();
		
		var meshFilter = GetComponent<MeshFilter>();
	    // sharedMesh is null during generation
	    // TODO: Fix this as the generator shows errors in the console when using mesh vs. sharedMesh
	    //mesh = (meshFilter.mesh if EditorApplication.isPlayingOrWillChangePlaymode else meshFilter.sharedMesh)
		if(Application.isPlaying) meshFilter.mesh = mesh;
		else meshFilter.sharedMesh = mesh;
		
		if(parent.colliderType == ColliderType.MeshColliderPerChunk) {
			var colliderMesh = new Mesh();
			colliderMesh.vertices = chunk.meshData.CollidableVertices.ToArray();
			colliderMesh.triangles = chunk.meshData.CollidableTriangles.ToArray();
			var meshCollider = GetComponent<MeshCollider>();
			if(colliderMesh != null) {
				if(meshCollider == null) meshCollider = gameObject.AddComponent<MeshCollider>();
			   	meshCollider.sharedMesh = colliderMesh;
			   	meshCollider.convex = false;
				meshCollider.enabled = true;
			}
			else {
				if(meshCollider != null) meshCollider.enabled = false;
			}
		}
		transform.localPosition = (chunk.gridPosition * parent.chunkDimensions).ToVector3() * parent.cubeSize;
	}
开发者ID:carriercomm,项目名称:cubed,代码行数:35,代码来源:ChunkBehaviour.cs

示例9: Generate

		public override Chunk Generate(IProgress<string> progress, int chunkX, int chunkY)
		{
			Reseed(chunkX, chunkY);

			var chunk = new Chunk(Width, Height);
			Fill(chunk, ChunkLayer.Background, _dirtId);
			Fill(chunk, ChunkLayer.Floor, _grassId);

			for (var x = 0; x < Width; x++)
			{
				for (var y = 0; y < Height; y++)
				{
					var value = SimplexNoise.Generate((chunkX * Width + x) / 256.0f, (chunkY * Height + y) / 256.0f);
					if (value < -0.5)
					{
						chunk[ChunkLayer.Floor, x, y] = _waterId;
						chunk[ChunkLayer.Background, x, y] = _waterId;
					}
					else if (value < -0.25)
					{
						chunk[ChunkLayer.Floor, x, y] = _sandId;
						chunk[ChunkLayer.Background, x, y] = _sandId;
					}
					else if (value > 0.5)
					{
						chunk[ChunkLayer.Blocking, x, y] = _stoneId;
						chunk[ChunkLayer.Background, x, y] = _dirtId;
					}
				}
			}

			chunk = GenerateBushes(progress, chunk);

			return chunk;
		}
开发者ID:treytomes,项目名称:ASCIIWorld2,代码行数:35,代码来源:OverworldChunkGenerator.cs

示例10: DoSkylighting

        private void DoSkylighting(Chunk c)
        {
            int csx = (int)c.Size.X;
            int csz = (int)c.Size.Y;
            for (int _x = 0; _x < csx; _x++)
            {
                for (int _z = 0; _z < csz; _z++)
                {
                    int x = (int)(c.Position.X * csx) + _x;
                    int z = (int)(c.Position.Y * csz) + _z;
                    for (int y = 0; y < c.HeightMap[x, z]; y++)
                    {
                        byte currentSkyLight = c.SkyLight[x,y,z];

                        byte currentBlock = c.Blocks[x, y, z];

                        Block currentBlockInfo = OpenMinecraft.Blocks.Get(currentBlock);

                        // SUNLIGHT
                        currentSkyLight = (byte)(currentSkyLight - currentBlockInfo.Stop - 1);

                        if (currentSkyLight < 0) currentSkyLight = 0;
                        if (currentSkyLight > 15) currentSkyLight = 15;

                        c.SkyLight[x, y, z]=currentSkyLight;
                    }
                }
            }
            c.Save();
        }
开发者ID:N3X15,项目名称:MineEdit,代码行数:30,代码来源:ShittyLighter.cs

示例11: GenerateTerrain

    protected virtual void GenerateTerrain(Chunk chunk, int x, int z)
    {
        int stoneHeight = LayerStoneBase(chunk.pos.x + x, chunk.pos.z + z);
        stoneHeight += LayerStoneNoise(chunk.pos.x + x, chunk.pos.z + z);

        int dirtHeight = stoneHeight + LayerDirt(chunk.pos.x + x, chunk.pos.z + z);
        //CreateTreeIfValid(x, z, chunk, dirtHeight);

        for (int y = 0; y < Config.Env.ChunkSize; y++)
        {

            if (y + chunk.pos.y <= stoneHeight)
            {
                SetBlock(chunk, "stone", new BlockPos(x, y, z));
            }
            else if (y + chunk.pos.y < dirtHeight)
            {
                SetBlock(chunk, "dirt", new BlockPos(x, y, z));
            }
            else if (y + chunk.pos.y == dirtHeight)
            {
                SetBlock(chunk, "grass", new BlockPos(x, y, z));
            }
            else if (y + chunk.pos.y == dirtHeight + 1 && GetNoise(x+chunk.pos.x, y + chunk.pos.y, z + chunk.pos.z, 10, 10, 1) > 5)
            {
                Block wildGrass = "wildgrass";
                wildGrass.data2 = (byte)(GetNoise(x + chunk.pos.x, y + chunk.pos.y, z + chunk.pos.z, 1, 155, 1)+100);

                SetBlock(chunk, wildGrass, new BlockPos(x, y, z));
            }

        }
    }
开发者ID:renokun,项目名称:Voxelmetric,代码行数:33,代码来源:TerrainGen.cs

示例12: GenerateTerrain

    protected virtual void GenerateTerrain(Chunk chunk, int x, int z)
    {
        //int stoneHeight = LayerStoneBase(chunk.pos.x + x, chunk.pos.z + z);
        //stoneHeight += LayerStoneNoise(chunk.pos.x + x, chunk.pos.z + z);
        int stoneHeight = stoneBaseHeight;
        int dirtHeight = stoneBaseHeight + LayerDirt(chunk.pos.x + x, chunk.pos.z + z);
        //CreateTreeIfValid(x, z, chunk, dirtHeight);

        for (int y = 0; y < Config.Env.ChunkSize; y++)
        {

            if (y + chunk.pos.y <= stoneHeight)
            {
                SetBlock(chunk, "stone", new BlockPos(x, y, z));
            }
            else if (y + chunk.pos.y < dirtHeight)
            {
                SetBlock(chunk, "dirt", new BlockPos(x, y, z));
            }
            else if (y + chunk.pos.y == dirtHeight)
            {
                SetBlock(chunk, "grass", new BlockPos(x, y, z));
            }

        }
    }
开发者ID:Dalez,项目名称:CubeCraft,代码行数:26,代码来源:TerrainGenFlat.cs

示例13: MeshGenerationJob

 public MeshGenerationJob(Chunk chunk, DensityProvider provider, Vector3 offset, Action<MeshProxy> callback)
 {
     this.provider = provider;
     this.offset = offset;
     this.callback = callback;
     this.chunk = chunk;
 }
开发者ID:JakeCataford,项目名称:infinite-level-generation,代码行数:7,代码来源:MeshGenerationJob.cs

示例14: GenerateSectionAsync

 public static Task<Result> GenerateSectionAsync(ILogger logger, Chunk chunk, Point center, SizeF scaleSize, ushort maxIterations)
 {
     return Task.Run(() =>
     {
         return GenerateSection(logger, chunk, center, scaleSize, maxIterations);
     });
 }
开发者ID:EBrown8534,项目名称:Fractals,代码行数:7,代码来源:Generator.cs

示例15: GenerateBlocks

        protected virtual void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                }
                else if (y > rockHeight) // dirt level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Dirt);
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX, worldPositionZ);
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:26,代码来源:BiomedTerrain.cs


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