コード例 #1
0
        void Update()
        {
            Vector2 currentChunkPos = GlobalPosToChunkCoord(transform.position);

            if (currentChunkPos != CenterChunkPos)
            {
                LoadNewChunks();
                CenterChunkPos = currentChunkPos;
            }

            if (LoadRenderChunkQueue.Count > 0)                                     // New chunks
            {
                RenderChunk rc = LoadRenderChunkQueue.Dequeue();
                rc.GenerateProceduralTerrain(Seed, Variance, Threshold, Scale, 5);
                rc.InitializeGameObject(mat);
                rc.RefreshChunkMesh();
                if (LoadRenderChunkQueue.Count == 0)
                {
                    GC.Collect();
                }
            }
            if (UpdateRenderChunkQueue.Count > 0)                                   // Existing chunks
            {
                RenderChunk rc = UpdateRenderChunkQueue.Dequeue();
                rc.RefreshChunkMesh();
                //Debug.Log("Refreshed renderchunk");
            }
        }
コード例 #2
0
 public Chunk(Vector3 lowerCoord)
 {
     LowerGlobalCoord = lowerCoord;
     RenderChunks     = new RenderChunk[numRenderChunks];
     for (int i = 0; i < numRenderChunks; i++)
     {
         RenderChunks[i] = new RenderChunk(new Vector3(LowerGlobalCoord.x, i * 16, LowerGlobalCoord.z));
     }
 }
コード例 #3
0
        public bool RemoveBlock(Vector3 globalPos)
        {
            Vector2     chunkPos    = GlobalPosToChunkCoord(globalPos);
            Chunk       chunk       = Chunks[chunkPos];
            RenderChunk renderChunk = chunk.GetRenderChunkByCoord(globalPos);

            if (renderChunk.RemoveBlock(globalPos))
            {
                UpdateRenderChunkQueue.Enqueue(renderChunk);
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public bool AddBlock(Vector3 globalPos, VoxelType voxelType)
        {
            Vector2     chunkPos    = GlobalPosToChunkCoord(globalPos);
            Chunk       chunk       = Chunks[chunkPos];
            RenderChunk renderChunk = chunk.GetRenderChunkByCoord(globalPos);

            if (renderChunk.AddBlock(globalPos, voxelType))
            {
                UpdateRenderChunkQueue.Enqueue(renderChunk);
                return(true);
            }
            return(false);
        }