| | |
| | | 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 |
| | |
| | | //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) |
| | | { |
| | |
| | | // tilemap.SetTile(tilePos, cachedTiles[i]); |
| | | // } |
| | | //} |
| | | BatchSetTiles(chunk, cachedTiles, gameManager.destroyedTiles); |
| | | BatchSetTiles(chunk, cachedTiles, destroyedTiles); |
| | | } |
| | | yield return null; |
| | | } |