데이터파이프라인 타워 부분 개선

This commit is contained in:
2026-02-01 11:31:50 +09:00
parent 9d870625ce
commit fe046611b0
43 changed files with 2181 additions and 45 deletions

138
TOWER_CSV_IMPORTER.md Normal file
View File

@@ -0,0 +1,138 @@
# Tower CSV Importer Guide
## Overview
The tower CSV importer allows you to create tower prefabs from CSV data in one step, similar to the monster importer.
## Files Created
1. **TowerDataComponent.cs** - Component that applies TowerData to a GameObject
2. **TowerPrefabSetup.cs** - Implementation of IPrefabSetup for tower prefab generation
3. **CSVToSOImporter.cs** - Generic CSV importer that works with any data type
## How to Use
### Step 1: Ensure Tower Template Exists
If you haven't created the TowerTemplate yet:
1. In Unity, go to `Tools > Data > Create Tower Template`
2. This creates `Assets/Data/Templates/TowerTemplate.prefab` with all required components:
- NetworkObject
- Building
- TowerDataComponent
- MeshFilter & MeshRenderer
- BoxCollider
- NavMeshObstacle
### Step 2: Update Tower.csv
Edit `GameData/Tower.csv` with your tower data. The CSV uses camelCase field names matching TowerData class:
```csv
id,memo,mana,manpower,sizeX,sizeY,maxHp,atkRange,atkDamage,atkIntervalSec,modelPath
1,타워,25,10,3,3,50,10,5,2,Assets/Meshes/building_tower_B_blue.fbx
2,,5,5,1,1,30,0,0,0,Assets/Meshes/building_tower_B_blue.fbx
```
**Field Descriptions:**
- `id`: Unique tower ID
- `memo`: Tower name/description
- `mana`: Mana cost to build
- `manpower`: Construction work required
- `sizeX`: Grid width
- `sizeY`: Grid length
- `maxHp`: Maximum health
- `atkRange`: Attack range
- `atkDamage`: Attack damage
- `atkIntervalSec`: Attack interval in seconds
- `modelPath`: Path to FBX model or mesh asset
### Step 3: Import CSV
In Unity, go to `Tools > Data > Import All CSV`
The importer will:
1. Create ScriptableObject files in `Assets/Data/ScriptableObjects/Tower/`
2. Create/Update prefabs in `Assets/Prefabs/Tower/`
3. Apply models from `modelPath` column
4. Configure components based on CSV data
5. Link TowerData to TowerDataComponent
### Step 4: Use Tower Prefabs
Your generated tower prefabs are ready to use in the BuildingManager system!
## File Structure After Import
```
Assets/
├── Data/
│ ├── ScriptableObjects/
│ │ └── Tower/ # SO files (generated from CSV)
│ │ ├── Tower1.asset
│ │ └── Tower2.asset
│ └── Templates/ # Template prefabs (created once)
│ └── TowerTemplate.prefab
├── Prefabs/
│ └── Tower/ # Generated tower prefabs
│ ├── Tower1.prefab
│ └── Tower2.prefab
└── GameData/
└── Tower.csv # Source data (editable)
```
## How It Works
### CSV Import Pipeline
```
Tower.csv (CSV data)
↓ CSVToSOImporter
TowerData (ScriptableObject)
↓ TowerPrefabSetup
Tower.prefab (GameObject with components)
```
### TowerPrefabSetup Logic
1. **TowerDataComponent**: Links TowerData SO to the prefab
2. **Model Application**: Loads and applies FBX model from modelPath
3. **Collider Setup**: Creates BoxCollider sized to tower dimensions
4. **Building Integration**: Converts TowerData to BuildingData for Building component
## Benefits
-**One-click import**: Import all towers from CSV at once
-**Consistent structure**: All towers have the same components
-**Easy updates**: Edit CSV and re-import to update all towers
-**Designer-friendly**: Non-programmers can add new towers
-**Type-safe**: TowerData class ensures data integrity
## Troubleshooting
**"No prefab setup found for Tower"**
- Make sure TowerPrefabSetup.cs is in the Assets/Scripts/Editor folder
- Restart Unity Editor to ensure the script is compiled
**"Template not found"**
- Run `Tools > Data > Create Tower Template` first
- Verify TowerTemplate.prefab exists in Assets/Data/Templates/
**Prefabs not created**
- Check the Console for error messages
- Verify Tower.csv exists in GameData folder
- Ensure modelPath in CSV points to valid assets
**Model not showing**
- Verify modelPath in CSV is correct
- Check that the FBX file exists at the specified path
- Ensure the model has valid materials assigned
## Customization
### Adding New Components to All Towers
1. Open `Assets/Data/Templates/TowerTemplate.prefab`
2. Add the component
3. Configure defaults
4. Save template
5. Re-import CSV to apply changes to new towers
### Modifying Existing Towers
- Edit the prefab directly (changes persist on next import)
- OR modify Tower.csv and re-import (will update SO link and model)
## Notes
- TowerDataComponent converts TowerData to BuildingData for compatibility with the existing Building system
- The importer creates prefabs if they don't exist, or updates existing ones
- Prefab edits (other than SO and model) are preserved on re-import
- CSV field names must match TowerData class property names exactly (case-sensitive, camelCase)