本文整理汇总了C#中Chunk类的典型用法代码示例。如果您正苦于以下问题:C# Chunk类的具体用法?C# Chunk怎么用?C# Chunk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chunk类属于命名空间,在下文中一共展示了Chunk类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: LoadChunk
/// <summary>
/// Load a chunk into the terrain object.
/// </summary>
/// <param name="terrain">The terrain.</param>
/// <param name="chunkIndex">The chunk index.</param>
/// <returns>The chunk.</returns>
public Chunk LoadChunk(VoxelTerrain terrain, Position chunkIndex)
{
// Deserialize or generate the chunk
Chunk chunk;
if (!this.serializer.TryDeserialiseChunk(chunkIndex, out chunk))
{
// Get the surface heights of the chunk
float[] surfaceHeights;
if (!terrain.SurfaceHeights.TryGetValue(chunkIndex.X, out surfaceHeights))
{
surfaceHeights = this.voxelGenerator.GenerateSurfaceHeights(chunkIndex.X);
terrain.SurfaceHeights.Add(chunkIndex.X, surfaceHeights);
}
// The chunk doesn't yet exist, so generate a new one
chunk = new Chunk();
this.voxelGenerator.Generate(chunk.Voxels, surfaceHeights, chunkIndex);
// Serialize the generated chunk
this.serializer.SerialiseChunk(chunk, chunkIndex);
}
// Add the chunk to the terrain object
terrain.Chunks.Add(chunkIndex, chunk);
return chunk;
}
开发者ID:andynygard,项目名称:game-dwarves,代码行数:33,代码来源:ChunkLoader.cs
示例17: GenerateChunk
/// <summary>
/// Generate a chunk and return it. The terrain object remains unmodified.
/// </summary>
/// <param name="terrain">The terrain.</param>
/// <param name="chunkIndex">The chunk index.</param>
/// <returns>The chunk.</returns>
public Chunk GenerateChunk(Terrain terrain, Vector2I chunkIndex)
{
Chunk chunk = new Chunk();
// Calculate the position of the chunk in world coordinates
var chunkPos = new Vector2I(chunkIndex.X * Chunk.SizeX, chunkIndex.Y * Chunk.SizeY);
// Get the surface heights for this chunk
int[] surfaceHeights = this.GenerateSurfaceHeights(chunkPos);
// For now, fill the terrain with mud under the surface
for (int x = 0; x < Chunk.SizeX; x++)
{
int surfaceHeight = surfaceHeights[x];
if (surfaceHeight > 0)
{
for (int y = 0; y < surfaceHeight; y++)
{
chunk[x, y] = new Block(BlockType.Dirt);
}
}
}
return chunk;
}
开发者ID:andynygard,项目名称:game-dwarves,代码行数:31,代码来源:TerrainChunkGenerator.cs
示例18: Update
// Update is called once per frame
void Update()
{
if (mousehold) {
if (!Input.GetMouseButton (0))
mousehold = false;
}
if ((!mousehold) && Input.GetMouseButton (0)) {
mousehold = true;
if (Input.GetKey (KeyCode.LeftShift)) {
depth = 3;
} else
depth = 2;
//create a target where we are pointing
// Vector3 mouse = Input.mousePosition;
// mouse.z = depth - (Camera.main.transform.position.z)-1;
//
// targetPosition = Camera.main.ScreenToWorldPoint (mouse);
// targetPosition.z = depth-1;
hostChunk = world.GetChunk(pos.x,pos.y,pos.z);
// pos.x = pos.x - hostChunk.pos.x;
// pos.y = pos.y - hostChunk.pos.y;
// pos.z = pos.z - hostChunk.pos.z;
update = true;
}
if (update)
{
update = false;
UpdateCube();
}
}
开发者ID:TwoClunkers,项目名称:Clunk-Genesis,代码行数:35,代码来源:SelectedCube+(copy).cs
示例19: ApplyBiome
public override void ApplyBiome(Chunk chunk, int groundLevel, int groundOffset, int worldPositionX, int worldPositionZ)
{
for (int y = 0; y < SnowDepth; y++)
{
BlockStorage.Blocks[groundOffset + y].Type = BlockType.Snow;
}
}
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:7,代码来源:AntarticTundra.cs
示例20: Blockdata
public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
{
// Check if block on top has a solid down face
if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.down)) {
meshData = FaceDataUp(chunk, x, y, z, meshData);
}
// Check if the block below has a solid up face
if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up)) {
meshData = FaceDataDown(chunk, x, y, z, meshData);
}
// Check if the block north has a solid south face
if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.south)) {
meshData = FaceDataNorth(chunk, x, y, z, meshData);
}
// Check if the block south has a solid north face
if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.north)) {
meshData = FaceDataSouth(chunk, x, y, z, meshData);
}
// Check if the block east has a solid west face
if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.west)) {
meshData = FaceDataEast(chunk, x, y, z, meshData);
}
// Check if the block west has a solid east face
if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.east)) {
meshData = FaceDataWest(chunk, x, y, z, meshData);
}
return meshData;
}
开发者ID:strauzen,项目名称:Voxels,代码行数:34,代码来源:Block.cs
注:本文中的Chunk类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论