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:
@@ -20,6 +20,8 @@ namespace BaseGames.Combat
|
||||
|
||||
private bool _isHurtBoxInvincible;
|
||||
private bool _isActive = true;
|
||||
// 所有者级去重保护:防止同一角色的多个 HurtBox 子节点在同一次 HitBox 激活中被重复伤害
|
||||
private HurtBoxOwnerGuard _ownerGuard;
|
||||
|
||||
// ── 事件频道 ──────────────────────────────────────────────────────────
|
||||
[SerializeField] private DamageInfoEventChannelSO _onDamageDealt;
|
||||
@@ -41,10 +43,14 @@ namespace BaseGames.Combat
|
||||
#endif
|
||||
private void Awake()
|
||||
{
|
||||
_owner = GetComponentInParent<IDamageable>();
|
||||
_owner = GetComponentInParent<IDamageable>();
|
||||
_statusEffectable = GetComponentInParent<IStatusEffectable>();
|
||||
if (_owner == null)
|
||||
Debug.LogWarning($"[HurtBox] {name}: 父节点中未找到 IDamageable 实现。", this);
|
||||
// 在角色根节点查找或自动创建 HurtBoxOwnerGuard(多 HurtBox 共享所有者时只有一个 Guard)
|
||||
_ownerGuard = transform.root.GetComponent<HurtBoxOwnerGuard>();
|
||||
if (_ownerGuard == null && _owner != null)
|
||||
_ownerGuard = transform.root.gameObject.AddComponent<HurtBoxOwnerGuard>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,6 +62,8 @@ namespace BaseGames.Combat
|
||||
{
|
||||
Vector3 resolvedHitPoint = hitPoint ?? transform.position;
|
||||
if (!_isActive || _owner == null) return;
|
||||
// 所有者级去重:同一 HitBox 激活期内多个 HurtBox 子节点只处理首次命中(共享 HP)
|
||||
if (_ownerGuard != null && !_ownerGuard.TryRegisterHit(info.HitActivationId)) return;
|
||||
|
||||
// 1. 无敌帧检查
|
||||
if ((_owner.IsInvincible || _isHurtBoxInvincible)
|
||||
|
||||
Reference in New Issue
Block a user