63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Northbound.Data;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
namespace Northbound
|
|
{
|
|
[RequireComponent(typeof(EnemyUnit))]
|
|
[RequireComponent(typeof(EnemyAIController))]
|
|
[RequireComponent(typeof(NavMeshAgent))]
|
|
[RequireComponent(typeof(NetworkObject))]
|
|
public class CreepDataComponent : MonoBehaviour
|
|
{
|
|
[Header("Data Reference")]
|
|
[Tooltip("ScriptableObject containing creep data")]
|
|
public CreepData creepData;
|
|
|
|
[Header("Auto-Apply Settings")]
|
|
[Tooltip("Automatically apply stats from creepData on Awake")]
|
|
public bool autoApplyOnAwake = true;
|
|
|
|
private void Awake()
|
|
{
|
|
if (autoApplyOnAwake && creepData != null)
|
|
{
|
|
ApplyCreepData();
|
|
}
|
|
}
|
|
|
|
public void ApplyCreepData()
|
|
{
|
|
if (creepData == null)
|
|
{
|
|
Debug.LogWarning("[CreepDataComponent] creepData is null", this);
|
|
return;
|
|
}
|
|
|
|
EnemyUnit enemyUnit = GetComponent<EnemyUnit>();
|
|
if (enemyUnit != null)
|
|
{
|
|
enemyUnit.maxHealth = creepData.maxHp;
|
|
}
|
|
|
|
EnemyAIController aiController = GetComponent<EnemyAIController>();
|
|
if (aiController != null)
|
|
{
|
|
aiController.moveSpeed = creepData.moveSpeed;
|
|
aiController.attackDamage = creepData.atkDamage;
|
|
aiController.attackRange = creepData.atkRange;
|
|
aiController.attackInterval = creepData.atkIntervalSec;
|
|
}
|
|
|
|
NavMeshAgent navAgent = GetComponent<NavMeshAgent>();
|
|
if (navAgent != null)
|
|
{
|
|
navAgent.speed = creepData.moveSpeed;
|
|
}
|
|
|
|
Debug.Log($"[CreepDataComponent] Applied data for {creepData.id} ({creepData.memo})", this);
|
|
}
|
|
}
|
|
}
|