데이터 파이프라인 개선 및 포탈 로직 생성
csv import 시 자동으로 완전한 프리팹이 생성될 수 있도록 함.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Northbound;
|
||||
using Northbound.Data;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
@@ -8,12 +9,11 @@ public class EnemyPortal : MonoBehaviour
|
||||
[System.Serializable]
|
||||
public class MonsterEntry
|
||||
{
|
||||
public Northbound.Data.MonsterData monsterData;
|
||||
public GameObject prefab;
|
||||
}
|
||||
|
||||
[Header("Spawn Settings")]
|
||||
[Tooltip("몬스터 데이터 목록 (Editor에서 자동 로드 가능)")]
|
||||
[Tooltip("몬스터 프리팹 목록 (Editor에서 자동 로드 가능)")]
|
||||
[SerializeField] private List<MonsterEntry> monsterEntries = new();
|
||||
|
||||
[Header("Cost Settings")]
|
||||
@@ -44,8 +44,15 @@ public class EnemyPortal : MonoBehaviour
|
||||
while (remainingCost > 0 && monsterEntries.Count > 0)
|
||||
{
|
||||
MonsterEntry selectedEntry = SelectMonsterByWeight();
|
||||
MonsterData monsterData = GetMonsterDataFromPrefab(selectedEntry.prefab);
|
||||
|
||||
if (selectedEntry.monsterData.cost > remainingCost)
|
||||
if (monsterData == null)
|
||||
{
|
||||
Debug.LogWarning($"[EnemyPortal] Could not find MonsterData on {selectedEntry.prefab.name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (monsterData.cost > remainingCost)
|
||||
{
|
||||
if (!CanSpawnAnyMonster(remainingCost))
|
||||
{
|
||||
@@ -55,7 +62,7 @@ public class EnemyPortal : MonoBehaviour
|
||||
}
|
||||
|
||||
SpawnEnemy(selectedEntry.prefab);
|
||||
remainingCost -= selectedEntry.monsterData.cost;
|
||||
remainingCost -= monsterData.cost;
|
||||
spawnedCount++;
|
||||
}
|
||||
|
||||
@@ -69,7 +76,8 @@ public class EnemyPortal : MonoBehaviour
|
||||
{
|
||||
foreach (var entry in monsterEntries)
|
||||
{
|
||||
if (entry.monsterData.cost <= remainingCost)
|
||||
MonsterData monsterData = GetMonsterDataFromPrefab(entry.prefab);
|
||||
if (monsterData != null && monsterData.cost <= remainingCost)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -82,7 +90,11 @@ public class EnemyPortal : MonoBehaviour
|
||||
float totalWeight = 0f;
|
||||
foreach (var entry in monsterEntries)
|
||||
{
|
||||
totalWeight += entry.monsterData.weight;
|
||||
MonsterData monsterData = GetMonsterDataFromPrefab(entry.prefab);
|
||||
if (monsterData != null)
|
||||
{
|
||||
totalWeight += monsterData.weight;
|
||||
}
|
||||
}
|
||||
|
||||
float randomValue = Random.Range(0f, totalWeight);
|
||||
@@ -90,16 +102,33 @@ public class EnemyPortal : MonoBehaviour
|
||||
|
||||
foreach (var entry in monsterEntries)
|
||||
{
|
||||
cumulativeWeight += entry.monsterData.weight;
|
||||
if (randomValue <= cumulativeWeight)
|
||||
MonsterData monsterData = GetMonsterDataFromPrefab(entry.prefab);
|
||||
if (monsterData != null)
|
||||
{
|
||||
return entry;
|
||||
cumulativeWeight += monsterData.weight;
|
||||
if (randomValue <= cumulativeWeight)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return monsterEntries[0];
|
||||
}
|
||||
|
||||
private MonsterData GetMonsterDataFromPrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab == null) return null;
|
||||
|
||||
MonsterDataComponent component = prefab.GetComponent<MonsterDataComponent>();
|
||||
if (component != null)
|
||||
{
|
||||
return component.monsterData;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SpawnEnemy(GameObject prefab)
|
||||
{
|
||||
GameObject enemy = Instantiate(prefab, transform);
|
||||
|
||||
Reference in New Issue
Block a user