示例#1
0
    public static void Update()
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkChecker.Update");

        if (isRefreshing)
        {
            return;
        }

        Vector2Int curChunk = PlayerController.GetCurrentChunkPos();

        // if player moved to another chunk or render distance is changed, then try to refresh chunks data.
        if (lastChunk != curChunk || lastRenderDistance != SettingsPanel.RenderDistance)
        {
            isRefreshing       = true;
            tmpChunk           = curChunk;
            lastRenderDistance = SettingsPanel.RenderDistance;

            // only load chunks in render distance (if render distance is greater than 6, then load chunks in 6)
            // and unload chunks out of render distance
            List <Vector2Int> loadChunks   = NBTHelper.GetLoadChunks(curChunk);
            List <Vector2Int> unloadChunks = NBTHelper.GetUnloadChunks(curChunk, SettingsPanel.RenderDistance);

            if (loadChunks.Count > 0 || unloadChunks.Count > 0)
            {
                ChunkManager.ChunksEnterLeaveViewReq(loadChunks, unloadChunks);
            }
            else
            {
                FinishRefresh();
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }