// Assets/Editor/DataImporter/CSVDebugger.cs using UnityEngine; using UnityEditor; using System.IO; using System.Text; namespace DigAndDefend.Editor { public static class CSVDebugger { [MenuItem("DigAndDefend/Debug CSV Files")] public static void DebugCSVFiles() { string gameDataPath = Path.Combine(Application.dataPath, "..", "GameData"); var csvFiles = Directory.GetFiles(gameDataPath, "*.csv"); Debug.Log("=== CSV 파일 디버그 ===\n"); foreach (var csvPath in csvFiles) { string fileName = Path.GetFileName(csvPath); if (fileName.StartsWith(".")) continue; Debug.Log($"📄 파일: {fileName}"); // 파일 크기 FileInfo fileInfo = new FileInfo(csvPath); Debug.Log($" 📊 크기: {fileInfo.Length} bytes"); // 인코딩 테스트 try { // UTF-8로 읽기 var lines = File.ReadAllLines(csvPath, Encoding.UTF8); Debug.Log($" ✅ UTF-8 읽기 성공: {lines.Length}줄"); // ⭐ 모든 줄 출력 for (int i = 0; i < lines.Length; i++) { string line = lines[i]; Debug.Log($" 📋 [{i}] 길이:{line.Length} | 내용: '{line}'"); // 특수문자 확인 if (string.IsNullOrWhiteSpace(line)) { Debug.Log($" ⚠️ 빈 줄 또는 공백만 있음"); } // 바이트 출력 (첫 20바이트만) byte[] bytes = Encoding.UTF8.GetBytes(line); string byteStr = ""; for (int j = 0; j < Mathf.Min(bytes.Length, 20); j++) { byteStr += $"{bytes[j]:X2} "; } if (bytes.Length > 20) byteStr += "..."; Debug.Log($" 바이트: {byteStr}"); } // BOM 체크 byte[] fileBytes = File.ReadAllBytes(csvPath); if (fileBytes.Length >= 3 && fileBytes[0] == 0xEF && fileBytes[1] == 0xBB && fileBytes[2] == 0xBF) { Debug.Log($" ℹ️ UTF-8 BOM 있음"); } else { Debug.Log($" ℹ️ BOM 없음"); } // 전체 파일 바이트 (처음 100바이트만) string fileBytesStr = ""; for (int i = 0; i < Mathf.Min(fileBytes.Length, 100); i++) { fileBytesStr += $"{fileBytes[i]:X2} "; if ((i + 1) % 20 == 0) fileBytesStr += "\n "; } Debug.Log($" 📦 파일 바이트 (처음 100):\n {fileBytesStr}"); } catch (System.Exception e) { Debug.LogError($" ❌ 읽기 실패: {e.Message}"); } Debug.Log(""); } Debug.Log("=== 디버그 완료 ==="); } } }