ThreeKingdomsSlingshot/Assets/Scripts/Editor/DataImporter.cs

99 lines
4.5 KiB
C#
Raw Normal View History

아웃게임 1차(PD #1093 세션 A) — 본영 로비 · 세이브 · 군량 · 영웅(레벨·승급 6칸·진화·스킬 표시) · 편성(전열 3/후열 2 · 프리셋 3) · 거래(뽑기·골드 장비 상점) · 스테이지 보상·별 3·소탕 - 데이터: 기획 tables/ 12장 → Assets/Data/OutGame/*.csv · 메뉴 TKS/Import OutGame Data(Editor/DataImporter) → Resources/OutGame 9 자산(HeroDb·GearDb·GachaConfig·EconomyConfig·RewardTable·LevelTable·PromotionTable·EvolveTable·SkillInfoDb) · 검증(행 수·필수 열·id 유일·hero↔skill↔gear·확률 합) 오류 시 자산 불변 · BalanceConfig.heroes[]/HeroDef 삭제 → HeroDb(기존 5인 id 유지) · economy.csv 키 17 + gacha.csv 키 2 추가(기획서 본문 값 · C45) - 세이브: persistentDataPath/save.json · ver 1 · 즉시 저장 · 오프라인 군량 회복 · 일일 초기화 · 신규 유저 = 유비·관우·장비·조운·황충 Lv1 녹 ★=희귀도 · 골드 1000 · 보옥 300 · 군량 30 · 테스트·캡처 = 메모리 전용 - 화면(uGUI 와이어프레임 · img03·06·08·11): 시작 = 본영 로비(출정 → 월드맵 · 편성 · 연무장/보물/내정 준비 중 · 동맹 추후) · 재화 바(월드맵 포함 · 군량 타이머) · 하단 탭 5 · ◀/Esc 일관 · 영웅 목록·상세·상세정보·도감 · 편성(탭·드래그) · 뽑기(천장 n/80 · 확률 공개 · 첫 10연 무료 · 10연 ★★ 보장 · 카드 순차 공개) · 장비 상점(흰/녹 6종 일일 · sell×5 · 새로고침 보옥 20) - 전투 연결: BattleManager.LineupProvider/Deployed(LineupEntry · §3-2 스탯 · 방어 배율 생성 뒤) · playerSpawnPoints = 전열 (−4/0/4, −12) · 후열 (−2/2, −14) · WorldMapScreen 훅(팝업 군량·보상·별 · 입장 군량 · 노드 별 star_on/off · 소탕 · ◀ 본영 · TopInset) · 결과 패널(별 3 조건 · 골드·경험·보옥·장비) · GameBootstrap/AutoPlayDriver 로비 시작 - B 세션 파일(ActionResolver·Combat·UnitView·BattleHUD·SlingshotInput·EnemyAI) 미변경 - 테스트 56/56(기존 41 유지 · 신규 OutGameTests 15) · console error 0 · 사본 GUI 캡처 11장(DataImporter.CaptureOutGame) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 12:11:10 +00:00
using System.IO;
using System.Text;
using TKS.OutGame;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace TKS.EditorTools
{
/// <summary>
/// 아웃게임 표(Assets/Data/OutGame/*.csv · 기획 tables/ 사본 12장) → ScriptableObject 9개(Assets/Resources/OutGame/).
/// 메뉴 TKS/Import OutGame Data 또는 CLI: Unity.exe -batchmode -nographics -projectPath &lt;proj&gt; -executeMethod TKS.EditorTools.DataImporter.Import -quit
/// 형식·참조 오류가 하나라도 있으면 자산을 건드리지 않는다(콘솔 error 로 행 번호 보고).
/// </summary>
public static class DataImporter
{
public const string AssetFolder = "Assets/Resources/OutGame";
[MenuItem("TKS/Import OutGame Data (아웃게임 데이터 임포트)")]
public static void Import()
{
ImportAll();
}
public static string[] ReadFiles()
{
var dir = Path.Combine(Application.dataPath, OutGameTables.Folder);
var texts = new string[OutGameTables.Files.Length];
for (int i = 0; i < texts.Length; i++)
{
var p = Path.Combine(dir, OutGameTables.Files[i]);
texts[i] = File.Exists(p) ? File.ReadAllText(p, Encoding.UTF8) : null;
}
return texts;
}
public static bool ImportAll()
{
var r = OutGameTables.Parse(ReadFiles());
if (r.errors.Count > 0)
{
foreach (var e in r.errors) Debug.LogError("[TKS] 아웃게임 표 오류 · " + e);
Debug.LogError("[TKS] 아웃게임 임포트 중단(오류 " + r.errors.Count + ") · 자산 변경 없음");
OutGameTables.Destroy(r);
return false;
}
if (!AssetDatabase.IsValidFolder("Assets/Resources")) AssetDatabase.CreateFolder("Assets", "Resources");
if (!AssetDatabase.IsValidFolder(AssetFolder)) AssetDatabase.CreateFolder("Assets/Resources", "OutGame");
foreach (var so in r.data.All)
{
var name = so.GetType().Name;
var path = AssetFolder + "/" + name + ".asset";
var existing = AssetDatabase.LoadAssetAtPath(path, so.GetType()) as ScriptableObject;
so.name = name;
if (existing == null) AssetDatabase.CreateAsset(so, path);
else
{
EditorUtility.CopySerialized(so, existing);
existing.name = name;
if (existing is HeroDb) ((HeroDb)existing).InvalidateIndex();
if (existing is GearDb) ((GearDb)existing).InvalidateIndex();
EditorUtility.SetDirty(existing);
Object.DestroyImmediate(so);
}
}
AssetDatabase.SaveAssets();
var sb = new StringBuilder("[TKS] 아웃게임 임포트 완료 ·");
foreach (var kv in r.rowCounts) sb.Append(' ').Append(kv.Key).Append(' ').Append(kv.Value);
Debug.Log(sb.Append(" · ").Append(AssetFolder).ToString());
return true;
}
/// <summary>
/// 아웃게임 화면 검증 캡처(GUI 에디터 · 사본 프로젝트 권장 · 세이브 = 메모리 전용이라 실제 save.json 불변):
/// Unity.exe -projectPath &lt;copy&gt; -executeMethod TKS.EditorTools.DataImporter.CaptureOutGame -outgameDir &lt;dir&gt;
/// 로비 · 영웅 목록 · 영웅 상세 · 편성 · 뽑기 · 뽑기 결과 · 월드맵 팝업 · 전투 결과 PNG + log · 끝나면 스스로 종료.
/// </summary>
public static void CaptureOutGame()
{
string dir = GetArg("-outgameDir");
if (string.IsNullOrEmpty(dir)) dir = Path.Combine(Directory.GetCurrentDirectory(), "Logs", "outgame_capture");
ImportAll();
EditorSceneManager.OpenScene(ProjectSetup.ScenePath, OpenSceneMode.Single);
SessionState.SetBool(SaveStore.MemoryFlagKey, true);
SessionState.SetString(OutGameCaptureDriver.DirKey, dir);
Debug.Log("[TKS] 아웃게임 캡처 시작 → " + dir);
EditorApplication.EnterPlaymode();
}
static string GetArg(string name)
{
var args = System.Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length - 1; i++)
if (args[i] == name) return args[i + 1];
return null;
}
}
}