本文整理汇总了C#中Chunk.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.Generate方法的具体用法?C# Chunk.Generate怎么用?C# Chunk.Generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk.Generate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateChunks
// Accesses the chunks from allChunks and assigns them into activeChunks
// OR if not in allChunks already, generates them, puts them in allChunks and activeChunks
IEnumerator ActivateChunks(List<int[]> indices)
{
int worldHeight = 1 * Settings.CHUNK_SIZE;
activeChunks = new List<Chunk>();
foreach (int[] index in indices)
{
string accessor = Util.CoordsToString(index);
Chunk c;
// Chunk is currently loaded into allChunks
if (allChunks.TryGetValue(accessor, out c))
{
activeChunks.Add(c);
if (c.myObj == null)
InstantiateChunk(c);
if (!c.rendering)
{
c.rendering = true;
c.chunkRenderer.Render();
}
}
// Chunk is not found, so we create it
else
{
c = new Chunk(octaves, multiplier, amplitude, lacunarity, index);
Vector3 location = new Vector3(index[0],index[1],index[2])*Settings.CHUNK_SIZE;
// Note that the location parameter unit is blocks, not chunks, nor meters
c.Generate(location, worldHeight);
InstantiateChunk(c);
c.rendering = true;
c.chunkRenderer.Render();
allChunks[accessor] = c;
activeChunks.Add(c);
}
yield return null;
}
}
示例2: FixedUpdate
void FixedUpdate () {
if (!PlayerShip.instance)
{
return;
}
player = PlayerShip.instance.gameObject;
for (int y = Mathf.FloorToInt(player.transform.position.y/chunkSize)-6;y <= Mathf.FloorToInt(player.transform.position.y/chunkSize)+6;y++) {
for (int x = Mathf.FloorToInt(player.transform.position.x/chunkSize)-6;x <= Mathf.FloorToInt(player.transform.position.x/chunkSize)+6;x++) {
int _x = Mathf.Clamp (x+levelSize/2,0, levelSize-1);
int _y = Mathf.Clamp (y+levelSize/2,0, levelSize-1);
if (!initializedChunks[_y,_x]) {
initializedChunks[_y,_x] = Instantiate (chunk, new Vector2(x*chunkSize, y*chunkSize),chunk.transform.rotation) as Chunk;
initializedChunks[_y,_x].transform.parent = transform;
}
}
}
foreach(Collider2D c in Physics2D.OverlapCircleAll(player.transform.position, chunkSize*4, 1<<15)) {
chunk = c.GetComponent<Chunk>();
if (chunk) {
chunk.Generate();
}
}
foreach(Collider2D c in Physics2D.OverlapCircleAll (player.transform.position, chunkSize*4, 1<<9)) {
EnemyShip e = c.GetComponent <EnemyShip>();
if(e!=null)
e.DespawnIn(15);
}
}