Files
ProjectMD/Assets/Editor/DataImporter/CSVDebugger.cs

94 lines
3.4 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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("=== 디버그 완료 ===");
}
}
}