Files
zeling_v2/Assets/_Game/Scripts/Combat/HitBoxColliderProxy.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

42 lines
1.6 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.Combat
{
/// <summary>
/// 子碰撞体代理。挂载在 HitBox 子节点上,将 Trigger 事件转发给父级 HitBox
/// 实现"单一 HitBox 组件 + 多个异形 Collider2D"的组合判定盒。
///
/// 配置说明(子节点多形状模式):
/// [AttackNode] ← HitBox 组件(本身可不带 Collider2D
/// ├── [Shape_Box] ← BoxCollider2D + HitBoxColliderProxy
/// └── [Shape_Circle] ← CircleCollider2D + HitBoxColliderProxy
///
/// ⚠️ 子节点 Collider2D 须设 IsTrigger = trueLayer 与父 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);
}
}