예제 #1
0
    IEnumerator CreateChunk()
    {
        Task GenerationTask;

        Vector3[] TempPositions = new Vector3[ChunksToGenerate.Count];
        ChunksToGenerate.CopyTo(TempPositions, 0);
        ChunksToGenerate.Clear();

        foreach (Vector3 pos in TempPositions)
        {
            if (chunks.Get(pos) == null)
            {
                generator = new WorldGeneration();
                WorldPos TempPos = new WorldPos((int)pos.x * Chunk.ChunkSize, (int)pos.y * Chunk.ChunkSize, (int)pos.z * Chunk.ChunkSize);

                yield return(Ninja.JumpToUnity);

                GameObject TempChunkObject = Instantiate(chunkPrefab) as GameObject;
                TempChunkObject.transform.SetParent(this.transform);
                TempChunkObject.name = TempPos.ToString();
                Chunk TempChunkScript = TempChunkObject.GetComponent <Chunk>();

                yield return(Ninja.JumpBack);

                TempChunkScript.world         = this;
                TempChunkScript.ChunkPosition = TempPos;
                this.StartCoroutineAsync(GenerateChunk(TempChunkScript), out GenerationTask);
                yield return(StartCoroutine(GenerationTask.Wait()));

                generator.FetchChunk(out TempChunkScript);
                chunks.Add(TempChunkScript, TempPos.ToVector3());
            }
        }
    }