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:
41
Assets/_Game/Scripts/Combat/HitBoxColliderProxy.cs
Normal file
41
Assets/_Game/Scripts/Combat/HitBoxColliderProxy.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 子碰撞体代理。挂载在 HitBox 子节点上,将 Trigger 事件转发给父级 HitBox,
|
||||
/// 实现"单一 HitBox 组件 + 多个异形 Collider2D"的组合判定盒。
|
||||
///
|
||||
/// 配置说明(子节点多形状模式):
|
||||
/// [AttackNode] ← HitBox 组件(本身可不带 Collider2D)
|
||||
/// ├── [Shape_Box] ← BoxCollider2D + HitBoxColliderProxy
|
||||
/// └── [Shape_Circle] ← CircleCollider2D + HitBoxColliderProxy
|
||||
///
|
||||
/// ⚠️ 子节点 Collider2D 须设 IsTrigger = true,Layer 与父 HitBox 一致。
|
||||
/// ⚠️ 无需手动调用 Init();HitBox.Awake() 自动完成注册。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public sealed class HitBoxColliderProxy : MonoBehaviour
|
||||
{
|
||||
private HitBox _owner;
|
||||
private Collider2D _col;
|
||||
|
||||
/// <summary>由父 HitBox.Awake() 调用,完成双向注册。</summary>
|
||||
internal void Init(HitBox owner)
|
||||
{
|
||||
_owner = owner;
|
||||
_col = GetComponent<Collider2D>();
|
||||
if (!_col.isTrigger)
|
||||
Debug.LogWarning($"[HitBoxColliderProxy] {name}: Collider2D.isTrigger 应为 true。", this);
|
||||
_col.enabled = false;
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool value)
|
||||
{
|
||||
if (_col != null) _col.enabled = value;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) => _owner?.HandleTriggerEnter(other, _col);
|
||||
private void OnTriggerExit2D(Collider2D other) => _owner?.HandleTriggerExit(other);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user