Files
zeling_v2/Assets/_Game/Scripts/Enemies/Perception/EnemyThreatAssessor.cs
Joywayer a1b4e629aa feat: Implement Room Streaming System
- Add RoomStreamingManager to manage room loading and unloading based on player proximity.
- Create StreamingBudgetConfigSO for memory and performance budgeting of the streaming system.
- Introduce TransitionDirector to handle seamless and atmospheric fade transitions between rooms.
- Develop WorldGraph to represent room connectivity and facilitate neighbor queries and distance calculations.
- Implement RoomNode and RoomEdge classes to structure room data and connections.
2026-05-23 19:10:29 +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"/>(原始 LOSBatchLOSSystem 写入)。</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;
}
}
}
}