using System.IO; using UnityEngine; using Utils; #if UNITY_EDITOR namespace Minigames.Examples { /// /// Debug tool for diagnosing photo loading issues. /// Add to any GameObject in scene, then right-click in Inspector to run tests. /// public class PhotoSystemDebugger : MonoBehaviour { [ContextMenu("1. Check Photo Files on Disk")] private void CheckPhotoFiles() { Debug.Log("=== CHECKING PHOTO FILES ON DISK ==="); CheckPhotoFilesForType(CaptureType.StatueMinigame); CheckPhotoFilesForType(CaptureType.DivingMinigame); } private void CheckPhotoFilesForType(CaptureType type) { string path = PhotoManager.GetCaptureDirectory(type); Debug.Log($"\n[{type}] Photo directory: {path}"); Debug.Log($"[{type}] Directory exists: {System.IO.Directory.Exists(path)}"); if (System.IO.Directory.Exists(path)) { var files = System.IO.Directory.GetFiles(path, "*.png"); Debug.Log($"[{type}] PNG files found: {files.Length}"); if (files.Length > 0) { foreach (var file in files) { var fileInfo = new System.IO.FileInfo(file); Debug.Log($" ✓ {System.IO.Path.GetFileName(file)} ({fileInfo.Length / 1024}KB)"); } } else { Debug.LogWarning($"[{type}] No PNG files found in directory!"); } } else { Debug.LogWarning($"[{type}] Directory does not exist! No photos captured yet."); } } [ContextMenu("2. Check Disk Photos")] private void CheckDiskPhotos() { Debug.Log("=== CHECKING DISK PHOTOS ==="); CheckPhotosForType(CaptureType.StatueMinigame); CheckPhotosForType(CaptureType.DivingMinigame); } private void CheckPhotosForType(CaptureType type) { string directory = PhotoManager.GetCaptureDirectory(type); Debug.Log($"\n[{type}] Photo directory: {directory}"); Debug.Log($"[{type}] Directory exists: {Directory.Exists(directory)}"); int count = PhotoManager.GetPhotoCount(type); Debug.Log($"[{type}] PhotoManager.GetPhotoCount(): {count}"); if (count > 0) { var photoIds = PhotoManager.GetPhotoIds(type, 10); // Show top 10 Debug.Log($"[{type}] Latest {photoIds.Count} photos:"); foreach (var id in photoIds) { string filePath = Path.Combine(directory, $"{id}.png"); if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); Debug.Log($" ✓ {id} - {fileInfo.CreationTime:yyyy-MM-dd HH:mm:ss} ({fileInfo.Length / 1024}KB)"); } else { Debug.LogWarning($" ✗ {id} - FILE MISSING!"); } } } else { Debug.LogWarning($"[{type}] No photos found on disk!"); } } [ContextMenu("3. Check AlbumPhotoSlot Components")] private void CheckAlbumPhotoSlots() { Debug.Log("=== CHECKING ALBUM PHOTO SLOTS ==="); var slots = FindObjectsByType(FindObjectsSortMode.None); Debug.Log($"\nAlbumPhotoSlot components found in scene: {slots.Length}"); if (slots.Length == 0) { Debug.LogError("❌ NO ALBUMPHOTOSLOT COMPONENTS FOUND!"); Debug.LogError("You need to add AlbumPhotoSlot components to GameObjects on your album pages."); return; } var statueSlots = 0; var divingSlots = 0; foreach (var slot in slots) { bool isActive = slot.gameObject.activeInHierarchy; string status = isActive ? "✓ ACTIVE" : "✗ INACTIVE"; Debug.Log($" {status} - {slot.gameObject.name}"); Debug.Log($" └─ CaptureType: {slot.CaptureType}"); Debug.Log($" └─ Scene Path: {GetGameObjectPath(slot.gameObject)}"); if (slot.CaptureType == CaptureType.StatueMinigame) statueSlots++; else if (slot.CaptureType == CaptureType.DivingMinigame) divingSlots++; if (!isActive) { Debug.LogWarning($" └─ WARNING: Slot is inactive! Make sure parent page is active when album opens."); } } Debug.Log($"\nSummary:"); Debug.Log($" StatueMinigame slots: {statueSlots}"); Debug.Log($" DivingMinigame slots: {divingSlots}"); } [ContextMenu("4. Check Album Page State")] private void CheckAlbumPageState() { Debug.Log("=== CHECKING ALBUM PAGE STATE ==="); var albumPage = FindFirstObjectByType(); if (albumPage == null) { Debug.LogError("❌ AlbumViewPage not found in scene!"); return; } Debug.Log($"\n✓ AlbumViewPage found: {albumPage.gameObject.name}"); Debug.Log($" └─ GameObject active: {albumPage.gameObject.activeInHierarchy}"); Debug.Log($" └─ Component enabled: {albumPage.enabled}"); // Check if album is currently open if (UI.Core.UIPageController.Instance != null) { bool isCurrentPage = UI.Core.UIPageController.Instance.CurrentPage == albumPage; Debug.Log($" └─ Is current page: {isCurrentPage}"); if (!isCurrentPage) { Debug.LogWarning("Album is not currently open. Photo controller won't initialize until album opens."); } } } [ContextMenu("5. Test Photo Loading Directly")] private void TestPhotoLoadingDirectly() { Debug.Log("=== TESTING DIRECT PHOTO LOADING ==="); TestLoadForType(CaptureType.StatueMinigame); TestLoadForType(CaptureType.DivingMinigame); } private void TestLoadForType(CaptureType type) { Debug.Log($"\n[{type}] Testing photo load..."); var photoIds = PhotoManager.GetPhotoIds(type, 1); if (photoIds.Count == 0) { Debug.LogWarning($"[{type}] No photos to load!"); return; } string photoId = photoIds[0]; Debug.Log($"[{type}] Attempting to load: {photoId}"); Texture2D photo = PhotoManager.LoadPhoto(type, photoId); if (photo != null) { Debug.Log($"[{type}] ✓ Photo loaded successfully!"); Debug.Log($" └─ Resolution: {photo.width}x{photo.height}"); Debug.Log($" └─ Format: {photo.format}"); // Clean up Destroy(photo); } else { Debug.LogError($"[{type}] ✗ Failed to load photo!"); Debug.LogError($" └─ Photo file may be missing or corrupted"); } } [ContextMenu("6. Run Full Diagnostic")] private void RunFullDiagnostic() { Debug.Log("╔════════════════════════════════════════════╗"); Debug.Log("║ PHOTO SYSTEM FULL DIAGNOSTIC ║"); Debug.Log("╚════════════════════════════════════════════╝"); CheckPhotoFiles(); Debug.Log("──────────────────────────────────────────────────"); CheckDiskPhotos(); Debug.Log("\n" + new string('─', 50) + "\n"); CheckAlbumPhotoSlots(); Debug.Log("\n" + new string('─', 50) + "\n"); CheckAlbumPageState(); Debug.Log("\n" + new string('─', 50) + "\n"); TestPhotoLoadingDirectly(); Debug.Log("\n╔════════════════════════════════════════════╗"); Debug.Log("║ DIAGNOSTIC COMPLETE ║"); Debug.Log("╚════════════════════════════════════════════╝"); } // Helper method to get full GameObject path private string GetGameObjectPath(GameObject obj) { string path = obj.name; Transform parent = obj.transform.parent; while (parent != null) { path = parent.name + "/" + path; parent = parent.parent; } return path; } } } #endif