miepzerino
2025-04-07 6b1abe7afb9350a7890f6b893f59f72a3988aaab
Assets/Scripts/GenerateTileMap.cs
@@ -28,6 +28,8 @@
    private const int CACHE_CLEAR_DISTANCE = 8; // Distance in chunks before clearing cache (should be > LOAD_DISTANCE)
    private Vector2Int lastCacheClearPosition; // Track position where cache was last cleared
    [NonSerialized]
    public List<Vector3Int> destroyedTiles = new List<Vector3Int>();
    private Dictionary<Vector2Int, bool> loadedChunks = new Dictionary<Vector2Int, bool>();
    private Dictionary<Vector2Int, TileBase[]> chunkCache = new Dictionary<Vector2Int, TileBase[]>();
    private Transform playerTransform; // Reference to player/camera
@@ -62,16 +64,16 @@
        //Debug.Log($"Current Chunk: {currentChunk}");
        if (currentChunk != lastLoadedChunk)
        {
            StartCoroutine(UpdateLoadedChunks(currentChunk, gameManager.destroyedTiles));
            StartCoroutine(UpdateLoadedChunks(currentChunk, destroyedTiles));
            lastLoadedChunk = currentChunk;
            // Check if we need to clear the cache
            ClearDistantChunks(currentChunk);
        }
    }
    public Dictionary<Vector2Int, TileBase[]> GetSaveData()
    public (int seed, Dictionary<Vector2Int, TileBase[]> chunkCache, List<Vector3Int> destroyedTiles) GetSaveValues()
    {
        return chunkCache;
        return (seed.Value, chunkCache, destroyedTiles);
    }
    public void LoadChunkDataFromSave(List<SerializedChunkData> serializedChunks)
    {
@@ -268,7 +270,7 @@
            //        tilemap.SetTile(tilePos, cachedTiles[i]);
            //    }
            //}
            BatchSetTiles(chunk, cachedTiles, gameManager.destroyedTiles);
            BatchSetTiles(chunk, cachedTiles, destroyedTiles);
        }
        yield return null;
    }