using UnityEngine; namespace BaseGames.Enemies.Perception { /// /// 威胁评估器:在原始 LOS 结果上叠加感知反应延迟,使敌人不会瞬间发现玩家。 /// /// 工作原理: /// /// 读取 (由 PhysicsPerceptionSystem 的 LOS/Sight 槽位驱动)。 /// 连续感知到玩家超过 秒后, 才变为 true。 /// 一旦丢失 LOS, 立即重置为 false(保持对"躲起来"的快速响应)。 /// /// /// 挂载:添加到与 相同的 GameObject。 /// 会自动路由至此组件(如果存在)。 /// [RequireComponent(typeof(EnemyBase))] public class EnemyThreatAssessor : MonoBehaviour { [Tooltip("持续感知此时长(s)后判定为威胁;模拟敌人的反应时间")] [SerializeField] [Min(0f)] private float reactionDelay = 0.15f; private EnemyBase _enemy; private float _losAccumulator; /// 是否已将玩家判定为当前威胁(含反应延迟)。 public bool IsThreatDetected { get; private set; } private void Awake() { _enemy = GetComponent(); } private void Update() { if (_enemy == null) return; bool hasLos = _enemy.HasLineOfSight; if (hasLos) { _losAccumulator += Time.deltaTime; if (_losAccumulator >= reactionDelay) IsThreatDetected = true; } else { _losAccumulator = 0f; IsThreatDetected = false; } } } }