using System.Collections.Generic; using UnityEngine; using Pooling; namespace Minigames.DivingForPictures { /// /// Manages a pool of trench tile objects to reduce garbage collection overhead. /// Optimized for handling a large number of different prefab types. /// public class TrenchTilePool : MultiPrefabPool { /// /// Returns a tile to the pool /// /// The tile to return to the pool /// The index of the prefab this tile was created from public void ReturnTile(GameObject tile, int prefabIndex) { if (tile != null) { Tile tileComponent = tile.GetComponent(); if (tileComponent != null) { Return(tileComponent, prefabIndex); } else { Debug.LogWarning($"Attempted to return a GameObject without a Tile component: {tile.name}"); Destroy(tile); } } } /// /// Gets a tile from the pool, or creates a new one if the pool is empty /// /// A tile instance ready to use public GameObject GetTile(int prefabIndex) { Tile tileComponent = Get(prefabIndex); return tileComponent.gameObject; } } }