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.
This commit is contained in:
61
Assets/_Game/Scripts/Enemies/AI/BD_IsOutsideZone.cs
Normal file
61
Assets/_Game/Scripts/Enemies/AI/BD_IsOutsideZone.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user