/// <summary>
        /// Destroys all chunks and internal engine structures - should be used only during shutdown
        /// </summary>
        public void DisposeAll()
        {
            StopGenerationThread();

            DestroyNavMesh();
            chunksPool             = null;
            chunksPoolCurrentIndex = -1;
            chunksPoolLoadIndex    = 0;
            chunksPoolFetchNew     = true;
            lastChunkFetch         = null;

            // Empty mesh jobs
            if (meshJobs != null)
            {
                for (int k = 0; k < meshJobs.Length; k++)
                {
                    if (meshJobs [k].vertices != null)
                    {
                        meshJobs [k].vertices.Clear();
                        meshJobs [k].vertices = null;
                    }
                    if (meshJobs [k].uv0 != null)
                    {
                        meshJobs [k].uv0.Clear();
                        meshJobs [k].uv0 = null;
                    }
                    if (meshJobs [k].uv2 != null)
                    {
                        meshJobs [k].uv2.Clear();
                        meshJobs [k].uv2 = null;
                    }
                    if (meshJobs [k].colors != null)
                    {
                        meshJobs [k].colors.Clear();
                        meshJobs [k].colors = null;
                    }
                    if (meshJobs [k].normals != null)
                    {
                        meshJobs [k].normals.Clear();
                        meshJobs [k].normals = null;
                    }
                    if (meshJobs [k].buffers != null)
                    {
                        for (int j = 0; j < MAX_MATERIALS_PER_CHUNK; j++)
                        {
                            if (meshJobs [k].buffers [j].indices != null)
                            {
                                meshJobs [k].buffers [j].indices.Clear();
                                meshJobs [k].buffers [j].indices      = null;
                                meshJobs [k].buffers [j].indicesArray = null;
                            }
                        }
                    }
                    if (meshJobs [k].colliderVertices != null)
                    {
                        meshJobs [k].colliderVertices.Clear();
                        meshJobs [k].colliderVertices = null;
                    }
                    if (meshJobs [k].colliderIndices != null)
                    {
                        meshJobs [k].colliderIndices.Clear();
                        meshJobs [k].colliderIndices = null;
                    }
                    if (meshJobs [k].navMeshVertices != null)
                    {
                        meshJobs [k].navMeshVertices.Clear();
                        meshJobs [k].navMeshVertices = null;
                    }
                    if (meshJobs [k].navMeshIndices != null)
                    {
                        meshJobs [k].navMeshIndices.Clear();
                        meshJobs [k].navMeshIndices = null;
                    }
                    if (meshJobs [k].mivs != null)
                    {
                        meshJobs [k].mivs.Clear();
                        meshJobs [k].mivs = null;
                    }
                }
            }

            // Destroy chunks
            if (cachedChunks != null)
            {
                foreach (KeyValuePair <int, CachedChunk> kv in cachedChunks)
                {
                    CachedChunk cc = kv.Value;
                    if (cc != null && cc.chunk != null)
                    {
                        DestroyImmediate(cc.chunk.gameObject);
                    }
                }
                cachedChunks.Clear();
            }
            chunkRequestLast = -1;
            cachedChunks     = null;

            if (worldRoot != null)
            {
                while (worldRoot.childCount > 0)
                {
                    DestroyImmediate(worldRoot.GetChild(0).gameObject);
                }
            }
            worldRoot  = null;
            cloudsRoot = null;
            chunksRoot = null;
            fxRoot     = null;

            lastChunkX = int.MaxValue;

            // Clear heightmap
            if (heightMapCache != null)
            {
                heightMapCache.Clear();
            }

            // Clear render queue
            chunkQueueRoot       = 0;
            lastChunkDistanceSqr = 0;

            ClearStats();

            // reset voxel definitions state values
            if (voxelDefinitions != null)
            {
                for (int k = 0; k < voxelDefinitions.Length; k++)
                {
                    VoxelDefinition vd = voxelDefinitions [k];
                    if (vd != null)
                    {
                        vd.Reset();
                    }
                }
            }

            initialized = false;
        }
        /// <summary>
        /// Destroys all chunks and internal engine structures - should be used only during shutdown
        /// </summary>
        public void DisposeAll()
        {
            StopGenerationThreads();
            DisposeRenderer();
            DestroyNavMesh();
            chunksPool             = null;
            chunksPoolCurrentIndex = -1;
            chunksPoolLoadIndex    = 0;
            chunksPoolFetchNew     = true;
            lastChunkFetch         = null;

            // Destroy chunks
            if (cachedChunks != null)
            {
                foreach (KeyValuePair <int, CachedChunk> kv in cachedChunks)
                {
                    CachedChunk cc = kv.Value;
                    if (cc != null && cc.chunk != null)
                    {
                        if (cc.chunk.mf != null && cc.chunk.mf.sharedMesh != null)
                        {
                            DestroyImmediate(cc.chunk.mf.sharedMesh);
                        }
                        if (cc.chunk.mc != null && cc.chunk.mc.sharedMesh != null)
                        {
                            DestroyImmediate(cc.chunk.mc.sharedMesh);
                        }
                        if (cc.chunk.navMesh != null)
                        {
                            DestroyImmediate(cc.chunk.navMesh);
                        }
                    }
                }
                cachedChunks.Clear();
            }
            chunkRequestLast = -1;
            cachedChunks     = null;

            DisposeTextures();

            if (worldRoot != null)
            {
                while (worldRoot.childCount > 0)
                {
                    DestroyImmediate(worldRoot.GetChild(0).gameObject);
                }
            }
            worldRoot  = null;
            cloudsRoot = null;
            chunksRoot = null;
            DestroyParticles();

            lastChunkX = int.MaxValue;

            // Clear heightmap
            if (heightMapCache != null)
            {
                heightMapCache.Clear();
            }

            // Clear render queue
            chunkQueueRoot       = 0;
            lastChunkDistanceSqr = 0;

            ClearStats();

            // reset voxel definitions state values
            if (voxelDefinitions != null)
            {
                for (int k = 0; k < voxelDefinitions.Length; k++)
                {
                    VoxelDefinition vd = voxelDefinitions [k];
                    if (vd != null)
                    {
                        vd.Reset();
                    }
                }
            }

            Resources.UnloadUnusedAssets();
            GC.Collect();

            initialized = false;
        }