using UnityEngine; namespace BaseGames.Enemies { /// /// 敌人运行时数值组件(架构 07_EnemyModule §2)。 /// 由 EnemyBase.Awake() 通过 Initialize(EnemyStatsSO) 注入配置。 /// public class EnemyStats : MonoBehaviour { private EnemyStatsSO _config; public int MaxHP { get; private set; } public int CurrentHP { get; private set; } public int Defense { get; private set; } public float AttackCooldownTimer { get; private set; } /// 每帧由 EnemyBase 更新(读取玩家位置后写入)。 public float DistanceToPlayer { get; set; } public void Initialize(EnemyStatsSO so) { _config = so; MaxHP = so.MaxHP; CurrentHP = so.MaxHP; Defense = so.Defense; } public void TakeDamage(int amount) { CurrentHP = Mathf.Max(0, CurrentHP - amount); } public void TickAttackCooldown(float dt) { if (AttackCooldownTimer > 0f) AttackCooldownTimer -= dt; } public void ResetAttackCooldown() { AttackCooldownTimer = _config != null ? _config.AttackCooldown : 1f; } } }