Files
zeling_v2/Assets/_Game/Scripts/Enemies/Perception/EnemyThreatAssessor.cs
Joywayer d27ae9407d feat: Enhance Physics Perception System with new detection modes and performance optimizations
- Updated PhysicsPerceptionSystem to support seven detection modes: RangeCircle, BatchLOS, FanCast, BoxCast, Sight, RayCast, and TriggerZone.
- Improved documentation for each detection mode, including performance optimization strategies.
- Introduced PerceptionTriggerProxy for event-driven detection in TriggerZone slots.
- Added SightBatchSystem to manage Sight slots efficiently, reducing CPU spikes during high enemy counts.
- Updated SensorSlotNames to reflect new detection modes and their purposes.
- Enhanced internal logic for detecting targets and managing detection events.
2026-06-02 23:18:20 +08:00

55 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
namespace BaseGames.Enemies.Perception
{
/// <summary>
/// 威胁评估器:在原始 LOS 结果上叠加感知反应延迟,使敌人不会瞬间发现玩家。
///
/// 工作原理:
/// <list type="bullet">
/// <item>读取 <see cref="EnemyBase.HasLineOfSight"/>(由 PhysicsPerceptionSystem 的 LOS/Sight 槽位驱动)。</item>
/// <item>连续感知到玩家超过 <see cref="reactionDelay"/> 秒后,<see cref="IsThreatDetected"/> 才变为 true。</item>
/// <item>一旦丢失 LOS<see cref="IsThreatDetected"/> 立即重置为 false保持对"躲起来"的快速响应)。</item>
/// </list>
///
/// 挂载:添加到与 <see cref="EnemyBase"/> 相同的 GameObject。
/// <see cref="EnemyBase.IsPlayerVisible()"/> 会自动路由至此组件(如果存在)。
/// </summary>
[RequireComponent(typeof(EnemyBase))]
public class EnemyThreatAssessor : MonoBehaviour
{
[Tooltip("持续感知此时长s后判定为威胁模拟敌人的反应时间")]
[SerializeField] [Min(0f)] private float reactionDelay = 0.15f;
private EnemyBase _enemy;
private float _losAccumulator;
/// <summary>是否已将玩家判定为当前威胁(含反应延迟)。</summary>
public bool IsThreatDetected { get; private set; }
private void Awake()
{
_enemy = GetComponent<EnemyBase>();
}
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;
}
}
}
}