Files
zeling_v2/Assets/_Game/Scripts/Enemies/AI/BD_IsOutsideZone.cs
Joywayer 06048c966a feat: Add HurtBoxOwnerGuard to prevent multiple damage registrations from the same HitBox activation
- Implemented HurtBoxOwnerGuard to ensure that multiple HurtBoxes on the same character do not register damage multiple times during a single HitBox activation.
- Added custom editor for HitBox to facilitate the creation of shape colliders with HitBoxColliderProxy.
- Introduced PhysicsPerceptionSystem for enemy perception, supporting multiple detection modes including RangeCircle, BatchLOS, FanCast, and BoxCast.
- Created EnemyPatrolZone to define patrol and chase areas for enemies, allowing for shared zones among multiple enemies.
- Added BD_IsOutsideZone conditional task for Behavior Designer to check if an enemy or player is outside a defined patrol zone.
2026-06-02 16:10:44 +08:00

62 lines
2.1 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.
#if GRAPH_DESIGNER
using UnityEngine;
using Opsive.BehaviorDesigner.Runtime.Tasks;
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
using BaseGames.Enemies;
namespace BaseGames.Enemies.AI
{
/// <summary>
/// BD Conditional判断目标坐标是否超出指定区域边界。
///
/// <list type="bullet">
/// <item>未配置 PatrolZone 时返回 Failure表示"无限制",等同于不超界)。</item>
/// <item>超界 → Success区域内 → Failure。</item>
/// </list>
///
/// 典型用法:在 Patrol BT 子树中用 BD_IsOutsideZone 检查敌人坐标,
/// 超出巡逻区域时触发归位序列。
/// </summary>
[TaskName("Is Outside Zone")]
[TaskCategory("BaseGames/Enemy/Zone")]
[TaskDescription("判断敌人/玩家坐标是否超出巡逻或追击区域;无 Zone 时返回 Failure不限制")]
public sealed class BD_IsOutsideZone : Conditional
{
[Tooltip("true = 检查追击区域false = 检查巡逻区域")]
[SerializeField] private bool m_CheckChaseZone = false;
[Tooltip("true = 检查敌人自身坐标false = 检查玩家坐标")]
[SerializeField] private bool m_CheckEnemy = true;
private EnemyBase _enemy;
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
public override TaskStatus OnUpdate()
{
if (_enemy == null) return TaskStatus.Failure;
var zone = _enemy.PatrolZone;
if (zone == null) return TaskStatus.Failure; // 无区域 = 不限制
Vector2 pos;
if (m_CheckEnemy)
{
pos = _enemy.transform.position;
}
else
{
if (_enemy.PlayerTransform == null) return TaskStatus.Failure;
pos = _enemy.PlayerTransform.position;
}
bool inside = m_CheckChaseZone
? zone.ContainsChase(pos)
: zone.ContainsPatrol(pos);
return inside ? TaskStatus.Failure : TaskStatus.Success;
}
}
}
#endif