本文整理汇总了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;
}
示例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;
}
示例3: ChunkDrawData
public ChunkDrawData(List<Vector3> vertexlist, List<int> trianglelist, List<Vector2> uvlist, Chunk chnk)
{
vertexList = vertexlist;
triangleList = trianglelist;
UVList = uvlist;
chunk = chnk;
}
示例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>();
}
}
}
}
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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));
}
}
}
示例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));
}
}
}
示例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;
}
示例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);
});
}
示例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);
}