- Implemented WeaponFeedback class for handling weapon-related feedbacks such as hit effects and attack sounds. - Added meta file for AddressableManagerWindow to manage addressable assets. - Included a new jump.data file for profiler data.
78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
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 Coroutine _returnCoroutine;
|
||
// 按 duration 缓存 WaitForSeconds,同一技能复用无 GC 分配
|
||
private WaitForSeconds _cachedWait;
|
||
private float _cachedWaitDuration = float.NaN;
|
||
|
||
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 秒后归还对象池(SetActive false)。
|
||
/// 由 SkillManager 对象池调用;替代旧版 Destroy 流程。
|
||
/// </summary>
|
||
public void AutoReturnAfter(float duration)
|
||
{
|
||
if (!Mathf.Approximately(_cachedWaitDuration, duration))
|
||
{
|
||
_cachedWaitDuration = duration;
|
||
_cachedWait = new WaitForSeconds(duration);
|
||
}
|
||
if (_returnCoroutine != null) StopCoroutine(_returnCoroutine);
|
||
_returnCoroutine = StartCoroutine(ReturnCoroutine());
|
||
}
|
||
|
||
private System.Collections.IEnumerator ReturnCoroutine()
|
||
{
|
||
yield return _cachedWait;
|
||
foreach (var hb in _hitBoxes)
|
||
hb?.Deactivate();
|
||
_returnCoroutine = null;
|
||
gameObject.SetActive(false); // 触发对象池回收
|
||
}
|
||
|
||
/// <summary>duration 秒后销毁(非池化路径,保留向后兼容)。</summary>
|
||
public void AutoDestroyAfter(float duration)
|
||
=> Destroy(gameObject, Mathf.Max(0f, duration));
|
||
|
||
private void OnDestroy()
|
||
{
|
||
foreach (var hb in _hitBoxes)
|
||
hb?.Deactivate();
|
||
}
|
||
}
|
||
}
|