From 40ac185dc7a017d95771fe580c77eab20e663908 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Tue, 08 Apr 2025 17:36:08 +0000 Subject: [PATCH] #46 added interactables --- Assets/Scripts/GenerateTileMap.cs | 74 +++++++++++++++++++------------------ 1 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Assets/Scripts/GenerateTileMap.cs b/Assets/Scripts/GenerateTileMap.cs index 8870c8e..0b3a588 100644 --- a/Assets/Scripts/GenerateTileMap.cs +++ b/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; } @@ -586,41 +588,41 @@ chunkCache.Clear(); } #if UNITY_EDITOR - private void OnDrawGizmos() - { - if (!Application.isPlaying) return; + //private void OnDrawGizmos() + //{ + // if (!Application.isPlaying) return; - // Draw current chunk boundaries - if (playerTransform != null) - { - Vector2Int currentChunk = GetChunkPosition(playerTransform.position); - Gizmos.color = Color.yellow; + // // Draw current chunk boundaries + // if (playerTransform != null) + // { + // Vector2Int currentChunk = GetChunkPosition(playerTransform.position); + // Gizmos.color = Color.yellow; - for (int x = -LOAD_DISTANCE; x <= LOAD_DISTANCE; x++) - { - for (int y = -LOAD_DISTANCE; y <= LOAD_DISTANCE; y++) - { - Vector2Int chunk = new Vector2Int(currentChunk.x + x, currentChunk.y + y); - Vector3 worldPos = new Vector3( - chunk.x * CHUNK_SIZE + transform.position.x, - chunk.y * CHUNK_SIZE + transform.position.y, - 0 - ); + // for (int x = -LOAD_DISTANCE; x <= LOAD_DISTANCE; x++) + // { + // for (int y = -LOAD_DISTANCE; y <= LOAD_DISTANCE; y++) + // { + // Vector2Int chunk = new Vector2Int(currentChunk.x + x, currentChunk.y + y); + // Vector3 worldPos = new Vector3( + // chunk.x * CHUNK_SIZE + transform.position.x, + // chunk.y * CHUNK_SIZE + transform.position.y, + // 0 + // ); - // Draw chunk boundary - Gizmos.DrawWireCube( - worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0), - new Vector3(CHUNK_SIZE, CHUNK_SIZE, 0) - ); + // // Draw chunk boundary + // Gizmos.DrawWireCube( + // worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0), + // new Vector3(CHUNK_SIZE, CHUNK_SIZE, 0) + // ); - // Draw chunk coordinates - UnityEditor.Handles.Label( - worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0), - $"({chunk.x}, {chunk.y})" - ); - } - } - } - } + // // Draw chunk coordinates + // UnityEditor.Handles.Label( + // worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0), + // $"({chunk.x}, {chunk.y})" + // ); + // } + // } + // } + //} #endif } -- Gitblit v1.9.3