121 lines
3.6 KiB
Markdown
121 lines
3.6 KiB
Markdown
# Automated Prefab Generation Pipeline
|
|
|
|
## Overview
|
|
This system automates the creation of monster prefabs from CSV data. No manual prefab setup required!
|
|
|
|
## How It Works
|
|
|
|
1. **CSV Data** → **ScriptableObject (SO)** → **Prefab** (automatically generated)
|
|
2. Template prefabs define required components and defaults
|
|
3. CSV importer creates complete prefabs with mesh, components, and SO references
|
|
|
|
## Setup Instructions
|
|
|
|
### Step 1: Create Template Prefab
|
|
|
|
1. In Unity, go to `Tools > Data > Create Monster Template`
|
|
2. This creates `Assets/Data/Templates/MonsterTemplate.prefab`
|
|
3. The template includes all required components:
|
|
- NetworkObject
|
|
- EnemyUnit
|
|
- MonsterDataComponent (links to SO)
|
|
- NavMeshAgent
|
|
- EnemyAIController
|
|
- CapsuleCollider
|
|
- MeshFilter & MeshRenderer
|
|
|
|
4. **Customize the template if needed:**
|
|
- Adjust default AI behavior
|
|
- Set default collider size
|
|
- Add visual effects
|
|
- Configure NavMeshAgent settings
|
|
|
|
### Step 2: Update CSV with Mesh Path
|
|
|
|
Add `meshPath` column to your `Monster.csv`:
|
|
|
|
```csv
|
|
id,name,memo,moveSpeed,maxHp,atkRange,atkDamage,atkIntervalSec,meshPath,cost,weight
|
|
101,Grunt,Basic Monster,2.6,30,1,3,1.2,Assets/Models/Monsters/Monster101.fbx,1,1.0
|
|
102,Fast,Fast/Weak,3.4,18,1,2,1,Assets/Models/Monsters/Monster102.fbx,2,0.5
|
|
```
|
|
|
|
### Step 3: Import Data
|
|
|
|
1. In Unity, go to `Tools > Data > Import All CSV`
|
|
2. The importer will:
|
|
- Create/update SO files in `Assets/Data/ScriptableObjects/Monster/`
|
|
- Create/update prefabs in `Assets/Prefabs/Monster/`
|
|
- Apply mesh from `meshPath` column
|
|
- Link SO reference to prefab's MonsterDataComponent
|
|
|
|
### Step 4: Use Prefabs
|
|
|
|
Your generated prefabs are ready to use! Example with EnemyPortal:
|
|
- Open EnemyPortal prefab
|
|
- Click "Load Monster Data" button
|
|
- All monster prefabs are automatically loaded
|
|
|
|
## File Structure
|
|
|
|
```
|
|
Assets/
|
|
├── Data/
|
|
│ ├── ScriptableObjects/
|
|
│ │ └── Monster/ # SO files (generated from CSV)
|
|
│ └── Templates/ # Template prefabs (created once)
|
|
│ └── MonsterTemplate.prefab
|
|
├── Prefabs/
|
|
│ └── Monster/ # Generated monster prefabs
|
|
│ ├── Monster101.prefab
|
|
│ ├── Monster102.prefab
|
|
│ └── ...
|
|
└── GameData/
|
|
└── Monster.csv # Source data (editable)
|
|
```
|
|
|
|
## Benefits
|
|
|
|
- ✅ **One source of truth**: Edit CSV, everything updates
|
|
- ✅ **No manual setup**: Prefabs generated automatically
|
|
- ✅ **Designer-friendly**: Templates visual, CSV simple
|
|
- ✅ **Error-proof**: All components guaranteed to exist
|
|
- ✅ **Easy customization**: Edit template once, applies to all
|
|
|
|
## Customization
|
|
|
|
### Adding New Components
|
|
1. Open `MonsterTemplate.prefab`
|
|
2. Add the component
|
|
3. Configure defaults
|
|
4. Save template
|
|
5. All future imports will include it
|
|
|
|
### Modifying Existing Monsters
|
|
- Edit the prefab directly (changes persist on next import)
|
|
- OR modify CSV and re-import (will update SO link and mesh)
|
|
|
|
### Creating Other Data Types
|
|
Use the same pattern:
|
|
1. Create template: `Tools > Data > Create Tower Template`
|
|
2. Add meshPath column to Tower.csv
|
|
3. Import: `Tools > Data > Import All CSV`
|
|
|
|
## Troubleshooting
|
|
|
|
**Prefab not created?**
|
|
- Check if template exists in `Assets/Data/Templates/`
|
|
- Verify `meshPath` column in CSV
|
|
|
|
**Mesh not showing?**
|
|
- Verify `meshPath` is correct in CSV
|
|
- Check that mesh file exists at specified path
|
|
|
|
**Components not configured?**
|
|
- Edit template prefab
|
|
- Re-import CSV to apply template changes to new prefabs
|
|
|
|
**Want to keep manual prefab edits?**
|
|
- Prefabs created by importer are NOT overwritten
|
|
- Edits persist on next import (SO and mesh only update)
|