데이터 파이프라인 개선 및 포탈 로직 생성
csv import 시 자동으로 완전한 프리팹이 생성될 수 있도록 함.
This commit is contained in:
154
GENERIC_IMPORTER.md
Normal file
154
GENERIC_IMPORTER.md
Normal file
@@ -0,0 +1,154 @@
|
||||
# Generic CSV Importer System
|
||||
|
||||
## Overview
|
||||
|
||||
The CSV importer now works with **any data type**, not just monsters! Each data type has its own prefab setup logic.
|
||||
|
||||
## How It Works
|
||||
|
||||
```
|
||||
CSV File (any type)
|
||||
↓ Importer
|
||||
ScriptableObject (data)
|
||||
↓ Prefab Setup
|
||||
Prefab (with components, models, etc.)
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### 1. IPrefabSetup Interface
|
||||
|
||||
```csharp
|
||||
public interface IPrefabSetup
|
||||
{
|
||||
string GetTemplateName(); // Which template to use
|
||||
void SetupPrefab(GameObject prefab, ScriptableObject data); // How to setup
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Prefab Setup Handlers
|
||||
|
||||
Each data type has its own setup class:
|
||||
|
||||
**MonsterPrefabSetup.cs**
|
||||
- Handles MonsterData
|
||||
- Applies FBX models
|
||||
- Sets Animator controllers
|
||||
- Updates MonsterDataComponent
|
||||
|
||||
**To add new types:**
|
||||
1. Create `NewTypePrefabSetup.cs` implementing `IPrefabSetup`
|
||||
2. Register in `CSVToSOImporter.RegisterPrefabSetups()`
|
||||
3. Done!
|
||||
|
||||
### 3. Templates
|
||||
|
||||
Each data type has its own template:
|
||||
```
|
||||
Assets/Data/Templates/
|
||||
├── MonsterTemplate.prefab → For monsters
|
||||
├── TowerTemplate.prefab → For towers (to create)
|
||||
└── PlayerTemplate.prefab → For players (to create)
|
||||
```
|
||||
|
||||
Templates define:
|
||||
- Required components
|
||||
- Component defaults
|
||||
- Layer settings
|
||||
- etc.
|
||||
|
||||
## Adding New Data Types
|
||||
|
||||
### Step 1: Create Template
|
||||
|
||||
```csharp
|
||||
// TemplateCreator.cs
|
||||
Tools > Data > Create [TypeName] Template
|
||||
```
|
||||
|
||||
### Step 2: Create Setup Handler
|
||||
|
||||
```csharp
|
||||
// TowerPrefabSetup.cs
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound.Editor
|
||||
{
|
||||
public class TowerPrefabSetup : IPrefabSetup
|
||||
{
|
||||
public string GetTemplateName()
|
||||
{
|
||||
return "TowerTemplate";
|
||||
}
|
||||
|
||||
public void SetupPrefab(GameObject prefab, ScriptableObject data)
|
||||
{
|
||||
// Your custom logic here
|
||||
// e.g., add models, apply stats, etc.
|
||||
Debug.Log($"[TowerPrefabSetup] Setting up {data.name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Register Handler
|
||||
|
||||
```csharp
|
||||
// CSVToSOImporter.cs - RegisterPrefabSetups()
|
||||
prefabSetups["Tower"] = new TowerPrefabSetup();
|
||||
```
|
||||
|
||||
### Step 4: Create CSV
|
||||
|
||||
```
|
||||
GameData/Tower.csv
|
||||
id,name,cost,...
|
||||
101,ArrowTower,50,...
|
||||
```
|
||||
|
||||
### Step 5: Import
|
||||
|
||||
```
|
||||
Tools > Data > Import All CSV
|
||||
```
|
||||
|
||||
Done! Prefabs auto-generated for Towers.
|
||||
|
||||
## Benefits
|
||||
|
||||
✅ **Generic**: Works for ANY data type
|
||||
✅ **Extensible**: Easy to add new types
|
||||
✅ **Type-Safe**: Each type has its own logic
|
||||
✅ **Maintainable**: No monster-specific code in importer
|
||||
✅ **Automated**: CSV → SO → Prefab in one click
|
||||
|
||||
## Example: Complete Flow for Monster
|
||||
|
||||
1. **Designer edits CSV**: `GameData/Monster.csv`
|
||||
2. **Imports data**: `Tools > Data > Import All CSV`
|
||||
3. **Importer**:
|
||||
- Reads CSV rows
|
||||
- Creates Monster101.asset (SO)
|
||||
- Clones MonsterTemplate.prefab
|
||||
- Calls MonsterPrefabSetup.SetupPrefab()
|
||||
- Saves as Monster101.prefab
|
||||
4. **MonsterPrefabSetup**:
|
||||
- Links SO to MonsterDataComponent
|
||||
- Applies FBX model
|
||||
- Sets Animator controller
|
||||
5. **Result**: Complete prefab ready to use!
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**"No prefab setup found for [Type]"**
|
||||
- Create `TypePrefabSetup.cs` implementing `IPrefabSetup`
|
||||
- Register it in `RegisterPrefabSetups()`
|
||||
|
||||
**"No template found for [Type]"**
|
||||
- Create `[Type]Template.prefab` using `Tools > Data > Create Template`
|
||||
- Ensure name matches `GetTemplateName()` return value
|
||||
|
||||
**Prefabs not updating**
|
||||
- Check that your setup logic is in `SetupPrefab()`
|
||||
- Verify SO fields are being read correctly
|
||||
Reference in New Issue
Block a user