122 lines
3.9 KiB
C#
122 lines
3.9 KiB
C#
// Assets/Editor/DataImporter/ImporterWindow.cs
|
|
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace DigAndDefend.Editor
|
|
{
|
|
public class ImporterWindow : EditorWindow
|
|
{
|
|
private Vector2 scrollPosition;
|
|
|
|
[MenuItem("DigAndDefend/Data Importer")]
|
|
public static void ShowWindow()
|
|
{
|
|
var window = GetWindow<ImporterWindow>("Data Importer");
|
|
window.minSize = new Vector2(400, 300);
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Label("CSV → ScriptableObject Importer", EditorStyles.boldLabel);
|
|
GUILayout.Space(10);
|
|
|
|
EditorGUILayout.HelpBox(
|
|
"GameData 폴더의 CSV 파일을 ScriptableObject로 변환합니다.\n" +
|
|
"자동 생성된 C# 클래스를 사용합니다.",
|
|
MessageType.Info
|
|
);
|
|
|
|
GUILayout.Space(10);
|
|
|
|
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
|
|
|
|
string gameDataPath = Path.Combine(Application.dataPath, "..", "GameData");
|
|
|
|
if (!Directory.Exists(gameDataPath))
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"GameData 폴더를 찾을 수 없습니다.",
|
|
MessageType.Warning
|
|
);
|
|
}
|
|
else
|
|
{
|
|
var csvFiles = Directory.GetFiles(gameDataPath, "*.csv")
|
|
.Where(f => !f.Contains("Backups") && !Path.GetFileName(f).StartsWith("."))
|
|
.ToArray();
|
|
|
|
if (csvFiles.Length == 0)
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"CSV 파일이 없습니다.\n" +
|
|
"sync-from-notion.ps1을 먼저 실행하세요.",
|
|
MessageType.Warning
|
|
);
|
|
}
|
|
else
|
|
{
|
|
GUILayout.Label("발견된 CSV 파일:", EditorStyles.boldLabel);
|
|
GUILayout.Space(5);
|
|
|
|
foreach (var filePath in csvFiles)
|
|
{
|
|
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
|
|
|
GUILayout.BeginHorizontal();
|
|
|
|
GUILayout.Label($"📊 {fileName}", GUILayout.Width(200));
|
|
|
|
if (GUILayout.Button("Import", GUILayout.Width(100)))
|
|
{
|
|
ImportSingle(fileName);
|
|
}
|
|
|
|
GUILayout.EndHorizontal();
|
|
}
|
|
}
|
|
}
|
|
|
|
GUILayout.EndScrollView();
|
|
|
|
GUILayout.Space(20);
|
|
|
|
GUI.backgroundColor = Color.green;
|
|
if (GUILayout.Button("Import All Data", GUILayout.Height(50)))
|
|
{
|
|
if (EditorUtility.DisplayDialog(
|
|
"전체 데이터 Import",
|
|
"모든 CSV 파일을 읽어서 ScriptableObject를 생성합니다.\n" +
|
|
"기존 파일은 덮어씌워집니다.",
|
|
"Import All",
|
|
"Cancel"))
|
|
{
|
|
CSVToSOImporter.ImportAll();
|
|
}
|
|
}
|
|
GUI.backgroundColor = Color.white;
|
|
|
|
GUILayout.Space(10);
|
|
|
|
EditorGUILayout.HelpBox(
|
|
"Import 후 Assets/Data/ScriptableObjects 폴더를 확인하세요.",
|
|
MessageType.None
|
|
);
|
|
}
|
|
|
|
private void ImportSingle(string schemaName)
|
|
{
|
|
if (EditorUtility.DisplayDialog(
|
|
$"{schemaName} Import",
|
|
$"{schemaName}.csv를 읽어서 ScriptableObject를 생성합니다.\n" +
|
|
"기존 파일은 덮어씌워집니다.",
|
|
"Import",
|
|
"Cancel"))
|
|
{
|
|
CSVToSOImporter.ImportSchema(schemaName);
|
|
}
|
|
}
|
|
}
|
|
} |