Files
zeling_v2/Assets/_Game/Scripts/Combat/SkillHitBoxInstance.cs

49 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;
using BaseGames.Combat;
namespace BaseGames.Combat
{
/// <summary>
/// 技能 HitBox 实例(架构 09_ProgressionModule §9 SkillHitBoxInstance
/// 挂载于技能 HitBox Prefab 根节点。
/// 命名规范: Assets/Prefabs/Skills/SKL_{skillId}_HitBox.prefab
///
/// Prefab 内部层级示例(近战 AoE 技能):
/// [SKL_SkySlash_HitBox]
/// └── [HitBox] ← 扇形/圆形 PolygonCollider2D
/// └── HitBox.cs
/// </summary>
public class SkillHitBoxInstance : MonoBehaviour
{
[SerializeField] private HitBox[] _hitBoxes; // 技能可有多个 HitBox多段伤害
public event System.Action<DamageInfo> OnHitConfirmed;
private void Awake()
{
foreach (var hb in _hitBoxes)
{
if (hb == null) continue;
hb.OnHitConfirmed += info => OnHitConfirmed?.Invoke(info);
}
}
/// <summary>激活所有 HitBox传入伤害数据源和攻击者 Transform。</summary>
public void Activate(DamageSourceSO source, Transform attacker)
{
foreach (var hb in _hitBoxes)
hb?.Activate(source, attacker);
}
/// <summary>duration 秒后自动销毁此 GameObject。</summary>
public void AutoDestroyAfter(float duration)
=> Destroy(gameObject, Mathf.Max(0f, duration));
private void OnDestroy()
{
foreach (var hb in _hitBoxes)
hb?.Deactivate();
}
}
}