摄像机区域的架构改动
This commit is contained in:
94
Assets/_Game/Scripts/Player/PlayerCombat.cs
Normal file
94
Assets/_Game/Scripts/Player/PlayerCombat.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Combat;
|
||||
|
||||
namespace BaseGames.Player
|
||||
{
|
||||
/// <summary>
|
||||
/// 玩家战斗组件。
|
||||
/// HitBox 随装备武器动态实例化到 [WeaponSocket] 子节点,通过 WeaponManager.ActiveHitBoxInstance 访问。
|
||||
/// </summary>
|
||||
public class PlayerCombat : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private WeaponManager _weaponManager;
|
||||
|
||||
private PlayerStats _stats;
|
||||
private WeaponHitBoxInstance _currentHitBoxInstance;
|
||||
|
||||
/// <summary>下劈 HitBox 命中确认事件(供 DownAttackState 订阅 pogo 弹跳逻辑)。</summary>
|
||||
public event System.Action<DamageInfo> OnDownHitConfirmed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_stats = GetComponentInParent<PlayerStats>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_weaponManager != null)
|
||||
_weaponManager.OnWeaponChanged += HandleWeaponChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_weaponManager != null)
|
||||
_weaponManager.OnWeaponChanged -= HandleWeaponChanged;
|
||||
UnsubscribeDownHit();
|
||||
}
|
||||
|
||||
private void HandleWeaponChanged(WeaponSO _)
|
||||
{
|
||||
UnsubscribeDownHit();
|
||||
_currentHitBoxInstance = _weaponManager.ActiveHitBoxInstance;
|
||||
if (_currentHitBoxInstance != null)
|
||||
_currentHitBoxInstance.OnDownHitConfirmed += HandleDownHitConfirmed;
|
||||
}
|
||||
|
||||
private void UnsubscribeDownHit()
|
||||
{
|
||||
if (_currentHitBoxInstance == null) return;
|
||||
_currentHitBoxInstance.OnDownHitConfirmed -= HandleDownHitConfirmed;
|
||||
_currentHitBoxInstance = null;
|
||||
}
|
||||
|
||||
private void HandleDownHitConfirmed(DamageInfo info) => OnDownHitConfirmed?.Invoke(info);
|
||||
|
||||
// ── 连击段伤害来源切换 ────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// 根据当前连招段切换 HitBox 的 DamageSource(由 AttackState 在每段开始时调用)。
|
||||
/// </summary>
|
||||
public void SetComboSegmentSource(int comboIndex)
|
||||
{
|
||||
WeaponSO w = _weaponManager?.ActiveWeapon;
|
||||
if (w == null) return;
|
||||
|
||||
DamageSourceSO src = comboIndex switch
|
||||
{
|
||||
0 => w.attack1Source,
|
||||
1 => w.attack2Source,
|
||||
2 => w.attack3Source,
|
||||
_ => w.attack1Source,
|
||||
};
|
||||
_weaponManager.ActiveHitBoxInstance?.SetDamageSource(AttackDirection.Ground, src);
|
||||
}
|
||||
|
||||
// ── HitBox 激活(由 State / AnimationEvent 调用)─────────────────────
|
||||
public void EnableWeaponHitBox(AttackDirection dir)
|
||||
{
|
||||
var source = _weaponManager?.ActiveWeapon?.GetSourceByDir(dir);
|
||||
_weaponManager?.ActiveHitBoxInstance?.Activate(dir, source, transform);
|
||||
}
|
||||
|
||||
public void DisableWeaponHitBox(AttackDirection dir)
|
||||
=> _weaponManager?.ActiveHitBoxInstance?.Deactivate(dir);
|
||||
|
||||
public void DisableAllWeaponHitBoxes()
|
||||
=> _weaponManager?.ActiveHitBoxInstance?.DeactivateAll();
|
||||
|
||||
/// <summary>命中确认回调:增加灵力(由 HurtBox.ReceiveDamage 步骤 7 的 HitConfirmed 事件订阅)。</summary>
|
||||
public void OnHitConfirmed(DamageInfo info)
|
||||
{
|
||||
int gain = _weaponManager?.ActiveWeapon?.soulPowerGain ?? 10;
|
||||
_stats?.AddSoulPower(gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user