2025-11-27 13:21:22 +00:00
|
|
|
using System.Collections;
|
2025-11-25 15:48:18 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Core;
|
|
|
|
|
using Core.Lifecycle;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2025-11-27 13:21:22 +00:00
|
|
|
using Utils;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
namespace Minigames.StatueDressup.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Manages photo gallery display with optimized memory usage.
|
|
|
|
|
/// Loads photos in pages and caches thumbnails to avoid loading 1000+ photos at once.
|
|
|
|
|
/// Supports grid view with thumbnail preview and enlarged view on selection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StatuePhotoGalleryController : ManagedBehaviour
|
|
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
public static StatuePhotoGalleryController Instance { get; private set; }
|
|
|
|
|
|
2025-11-25 15:48:18 +01:00
|
|
|
[Header("Gallery UI")]
|
|
|
|
|
[SerializeField] private Transform gridContainer;
|
|
|
|
|
[SerializeField] private PhotoGridItem gridItemPrefab;
|
|
|
|
|
|
|
|
|
|
[Header("Enlarged View")]
|
2025-11-27 13:21:22 +00:00
|
|
|
[SerializeField] private Transform enlargedContainer; // Container for enlarged preview (top layer)
|
|
|
|
|
[SerializeField] private GameObject backdrop; // Dark backdrop for enlarged view
|
|
|
|
|
[SerializeField] private GameObject enlargedPreviewPrefab; // Prefab for enlarged preview (same as grid item)
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
[Header("Pagination")]
|
2025-11-27 13:21:22 +00:00
|
|
|
[SerializeField] private Button previousPageButton;
|
|
|
|
|
[SerializeField] private Button nextPageButton;
|
|
|
|
|
[SerializeField] private Text pageStatusText;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
private int currentPage;
|
|
|
|
|
private List<string> allPhotoIds = new List<string>();
|
|
|
|
|
private Dictionary<string, PhotoGridItem> activeGridItems = new Dictionary<string, PhotoGridItem>();
|
|
|
|
|
private Dictionary<string, Texture2D> thumbnailCache = new Dictionary<string, Texture2D>();
|
|
|
|
|
private Dictionary<string, Texture2D> fullPhotoCache = new Dictionary<string, Texture2D>(); // Cache full photos for enlargement
|
|
|
|
|
private Queue<string> thumbnailCacheOrder = new Queue<string>();
|
|
|
|
|
private bool isLoadingPage;
|
|
|
|
|
private PhotoEnlargeController enlargeController;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
internal override void OnManagedAwake()
|
|
|
|
|
{
|
|
|
|
|
base.OnManagedAwake();
|
|
|
|
|
|
|
|
|
|
// Singleton pattern
|
|
|
|
|
if (Instance != null && Instance != this)
|
|
|
|
|
{
|
|
|
|
|
Logging.Warning("[StatuePhotoGalleryController] Duplicate instance detected. Destroying duplicate.");
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
internal override void OnManagedStart()
|
|
|
|
|
{
|
|
|
|
|
base.OnManagedStart();
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Wait for data manager to be ready before initializing
|
|
|
|
|
DecorationDataManager.WhenReady(() =>
|
|
|
|
|
{
|
|
|
|
|
InitializeGallery();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize gallery once data manager is ready
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitializeGallery()
|
|
|
|
|
{
|
|
|
|
|
var settings = DecorationDataManager.Instance?.Settings;
|
|
|
|
|
|
|
|
|
|
// Initialize enlarge controller
|
|
|
|
|
enlargeController = new PhotoEnlargeController(backdrop, enlargedContainer,
|
|
|
|
|
settings?.GalleryAnimationDuration ?? StatueDressupConstants.DefaultAnimationDuration);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Setup page navigation buttons
|
|
|
|
|
if (previousPageButton != null)
|
|
|
|
|
previousPageButton.onClick.AddListener(OnPreviousPageClicked);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
if (nextPageButton != null)
|
|
|
|
|
nextPageButton.onClick.AddListener(OnNextPageClicked);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Hide backdrop initially
|
|
|
|
|
if (backdrop != null)
|
|
|
|
|
backdrop.SetActive(false);
|
|
|
|
|
|
|
|
|
|
// Clear grid initially (in case there are leftover items from scene setup)
|
|
|
|
|
ClearGrid();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Load first page
|
|
|
|
|
RefreshGallery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refresh the entire gallery from scratch
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RefreshGallery()
|
|
|
|
|
{
|
|
|
|
|
// Clear existing items
|
2025-11-27 13:21:22 +00:00
|
|
|
ClearGrid();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Get all photo IDs
|
2025-11-27 13:21:22 +00:00
|
|
|
allPhotoIds = PhotoManager.GetAllPhotoIds(CaptureType.StatueMinigame);
|
|
|
|
|
currentPage = 0;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Gallery refreshed: {allPhotoIds.Count} photos");
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Display first page
|
|
|
|
|
DisplayCurrentPage();
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
/// Display the current page of photos (clears grid and shows only current page)
|
2025-11-25 15:48:18 +01:00
|
|
|
/// </summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
private void DisplayCurrentPage()
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (isLoadingPage) return;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
isLoadingPage = true;
|
|
|
|
|
|
|
|
|
|
// Clear current grid
|
|
|
|
|
ClearGrid();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Get photos for current page
|
|
|
|
|
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
|
|
|
|
List<string> pagePhotoIds = PhotoManager.GetPhotoIdsPage(CaptureType.StatueMinigame, currentPage, itemsPerPage);
|
|
|
|
|
|
|
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Displaying page {currentPage + 1}: {pagePhotoIds.Count} items");
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Spawn grid items for this page
|
|
|
|
|
foreach (string photoId in pagePhotoIds)
|
|
|
|
|
{
|
|
|
|
|
SpawnGridItem(photoId);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Update button states
|
|
|
|
|
UpdatePageButtons();
|
|
|
|
|
|
|
|
|
|
// Update status text
|
|
|
|
|
int totalPages = Mathf.CeilToInt((float)allPhotoIds.Count / itemsPerPage);
|
|
|
|
|
UpdateStatusText($"Page {currentPage + 1}/{totalPages} ({allPhotoIds.Count} photos)");
|
|
|
|
|
|
|
|
|
|
isLoadingPage = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update page navigation button states
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdatePageButtons()
|
|
|
|
|
{
|
|
|
|
|
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
|
|
|
|
int totalPages = Mathf.CeilToInt((float)allPhotoIds.Count / itemsPerPage);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Enable/disable previous button
|
|
|
|
|
if (previousPageButton != null)
|
|
|
|
|
{
|
|
|
|
|
previousPageButton.interactable = currentPage > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enable/disable next button
|
|
|
|
|
if (nextPageButton != null)
|
|
|
|
|
{
|
|
|
|
|
nextPageButton.interactable = currentPage < totalPages - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Navigate to previous page
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OnPreviousPageClicked()
|
|
|
|
|
{
|
|
|
|
|
if (currentPage > 0)
|
|
|
|
|
{
|
|
|
|
|
currentPage--;
|
|
|
|
|
DisplayCurrentPage();
|
|
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Navigated to previous page: {currentPage}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Navigate to next page
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OnNextPageClicked()
|
|
|
|
|
{
|
|
|
|
|
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
|
|
|
|
int totalPages = Mathf.CeilToInt((float)allPhotoIds.Count / itemsPerPage);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
if (currentPage < totalPages - 1)
|
|
|
|
|
{
|
|
|
|
|
currentPage++;
|
|
|
|
|
DisplayCurrentPage();
|
|
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Navigated to next page: {currentPage}");
|
|
|
|
|
}
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spawn a grid item for a photo
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SpawnGridItem(string photoId)
|
|
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (activeGridItems.ContainsKey(photoId))
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
Logging.Warning($"[StatuePhotoGalleryController] Grid item already exists: {photoId}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhotoGridItem gridItem = Instantiate(gridItemPrefab, gridContainer);
|
|
|
|
|
gridItem.Initialize(photoId, this);
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
activeGridItems[photoId] = gridItem;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Load thumbnail asynchronously
|
|
|
|
|
StartCoroutine(LoadThumbnailAsync(photoId, gridItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Load thumbnail for grid item (async to avoid frame hitches)
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerator LoadThumbnailAsync(string photoId, PhotoGridItem gridItem)
|
|
|
|
|
{
|
|
|
|
|
// Check cache first
|
2025-11-27 13:21:22 +00:00
|
|
|
if (thumbnailCache.TryGetValue(photoId, out Texture2D cachedThumbnail))
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
gridItem.SetThumbnail(cachedThumbnail);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Yield to avoid loading all thumbnails in one frame
|
|
|
|
|
yield return null;
|
|
|
|
|
|
|
|
|
|
// Load full photo
|
2025-11-27 13:21:22 +00:00
|
|
|
Texture2D fullPhoto = PhotoManager.LoadPhoto(CaptureType.StatueMinigame, photoId);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
if (fullPhoto == null)
|
|
|
|
|
{
|
|
|
|
|
Logging.Warning($"[StatuePhotoGalleryController] Failed to load photo: {photoId}");
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create thumbnail
|
2025-11-27 13:21:22 +00:00
|
|
|
int thumbSize = DecorationDataManager.Instance?.Settings?.GalleryThumbnailSize ?? StatueDressupConstants.DefaultThumbnailSize;
|
|
|
|
|
Texture2D thumbnail = PhotoManager.CreateThumbnail(fullPhoto, thumbSize);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Destroy full photo immediately (we only need thumbnail)
|
|
|
|
|
Destroy(fullPhoto);
|
|
|
|
|
|
|
|
|
|
// Cache thumbnail
|
|
|
|
|
CacheThumbnail(photoId, thumbnail);
|
|
|
|
|
|
|
|
|
|
// Set on grid item
|
|
|
|
|
if (gridItem != null)
|
|
|
|
|
{
|
|
|
|
|
gridItem.SetThumbnail(thumbnail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cache thumbnail with LRU eviction
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void CacheThumbnail(string photoId, Texture2D thumbnail)
|
|
|
|
|
{
|
|
|
|
|
// Add to cache
|
2025-11-27 13:21:22 +00:00
|
|
|
thumbnailCache[photoId] = thumbnail;
|
|
|
|
|
thumbnailCacheOrder.Enqueue(photoId);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Evict oldest if over limit
|
2025-11-27 13:21:22 +00:00
|
|
|
int maxCached = DecorationDataManager.Instance?.Settings?.GalleryMaxCachedThumbnails ?? StatueDressupConstants.DefaultMaxCachedThumbnails;
|
|
|
|
|
while (thumbnailCache.Count > maxCached && thumbnailCacheOrder.Count > 0)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
string oldestId = thumbnailCacheOrder.Dequeue();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
if (thumbnailCache.TryGetValue(oldestId, out Texture2D oldThumbnail))
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
Destroy(oldThumbnail);
|
2025-11-27 13:21:22 +00:00
|
|
|
thumbnailCache.Remove(oldestId);
|
2025-11-25 15:48:18 +01:00
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Evicted thumbnail from cache: {oldestId}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
/// Enlarge a photo (called by PhotoGridItem)
|
2025-11-25 15:48:18 +01:00
|
|
|
/// </summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
public void OnGridItemClicked(PhotoGridItem gridItem, string photoId)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (enlargeController == null)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
Logging.Error("[StatuePhotoGalleryController] Enlarge controller not initialized");
|
2025-11-25 15:48:18 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// If already enlarged, shrink it
|
|
|
|
|
if (enlargeController.IsPhotoEnlarged)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
enlargeController.ShrinkPhoto();
|
2025-11-25 15:48:18 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Enlarging photo: {photoId}");
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
float enlargedScale = DecorationDataManager.Instance?.Settings?.GalleryEnlargedScale ?? StatueDressupConstants.DefaultEnlargedScale;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Check cache first
|
|
|
|
|
if (fullPhotoCache.TryGetValue(photoId, out Texture2D fullPhoto))
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
// Use cached photo
|
|
|
|
|
enlargeController.EnlargePhoto(gridItem, enlargedPreviewPrefab != null ? enlargedPreviewPrefab : gridItem.gameObject, fullPhoto, enlargedScale);
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
2025-11-27 13:21:22 +00:00
|
|
|
else
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
// Load full-size photo
|
|
|
|
|
fullPhoto = PhotoManager.LoadPhoto(CaptureType.StatueMinigame, photoId);
|
|
|
|
|
|
|
|
|
|
if (fullPhoto == null)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
Logging.Error($"[StatuePhotoGalleryController] Failed to load photo: {photoId}");
|
|
|
|
|
return;
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Cache it (limited cache)
|
|
|
|
|
if (fullPhotoCache.Count < 10) // Keep only recent 10 full photos
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
fullPhotoCache[photoId] = fullPhoto;
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
enlargeController.EnlargePhoto(gridItem, enlargedPreviewPrefab != null ? enlargedPreviewPrefab : gridItem.gameObject, fullPhoto, enlargedScale);
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
/// Cleanup when gallery is closed
|
2025-11-25 15:48:18 +01:00
|
|
|
/// </summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
public void CleanupGallery()
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (enlargeController != null)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
enlargeController.Cleanup();
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
2025-11-27 13:21:22 +00:00
|
|
|
|
|
|
|
|
// Clean up cached full photos
|
|
|
|
|
foreach (var photo in fullPhotoCache.Values)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (photo != null)
|
|
|
|
|
{
|
|
|
|
|
Destroy(photo);
|
|
|
|
|
}
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
2025-11-27 13:21:22 +00:00
|
|
|
fullPhotoCache.Clear();
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update status text
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateStatusText(string message)
|
|
|
|
|
{
|
2025-11-27 13:21:22 +00:00
|
|
|
if (pageStatusText != null)
|
|
|
|
|
pageStatusText.text = message;
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
Logging.Debug($"[StatuePhotoGalleryController] Status: {message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
/// Clear only the grid items (used when switching pages)
|
2025-11-25 15:48:18 +01:00
|
|
|
/// </summary>
|
2025-11-27 13:21:22 +00:00
|
|
|
private void ClearGrid()
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
// Destroy grid items
|
2025-11-27 13:21:22 +00:00
|
|
|
foreach (var gridItem in activeGridItems.Values)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
if (gridItem != null)
|
|
|
|
|
Destroy(gridItem.gameObject);
|
|
|
|
|
}
|
2025-11-27 13:21:22 +00:00
|
|
|
activeGridItems.Clear();
|
|
|
|
|
|
|
|
|
|
Logging.Debug("[StatuePhotoGalleryController] Grid cleared");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear all grid items and cached data (full cleanup)
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ClearGallery()
|
|
|
|
|
{
|
|
|
|
|
ClearGrid();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Clear thumbnail cache
|
2025-11-27 13:21:22 +00:00
|
|
|
foreach (var thumbnail in thumbnailCache.Values)
|
2025-11-25 15:48:18 +01:00
|
|
|
{
|
|
|
|
|
if (thumbnail != null)
|
|
|
|
|
Destroy(thumbnail);
|
|
|
|
|
}
|
2025-11-27 13:21:22 +00:00
|
|
|
thumbnailCache.Clear();
|
|
|
|
|
thumbnailCacheOrder.Clear();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
Logging.Debug("[StatuePhotoGalleryController] Gallery fully cleared");
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override void OnManagedDestroy()
|
|
|
|
|
{
|
|
|
|
|
base.OnManagedDestroy();
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
// Singleton cleanup
|
|
|
|
|
if (Instance == this)
|
|
|
|
|
{
|
|
|
|
|
Instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clean up cached textures
|
2025-11-25 15:48:18 +01:00
|
|
|
ClearGallery();
|
2025-11-27 13:21:22 +00:00
|
|
|
CleanupGallery();
|
2025-11-25 15:48:18 +01:00
|
|
|
|
|
|
|
|
// Unsubscribe buttons
|
2025-11-27 13:21:22 +00:00
|
|
|
if (previousPageButton != null)
|
|
|
|
|
previousPageButton.onClick.RemoveListener(OnPreviousPageClicked);
|
2025-11-25 15:48:18 +01:00
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
if (nextPageButton != null)
|
|
|
|
|
nextPageButton.onClick.RemoveListener(OnNextPageClicked);
|
2025-11-25 15:48:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:21:22 +00:00
|
|
|
|