多轮审查和修复

This commit is contained in:
2026-05-12 15:34:08 +08:00
parent f55d2a57c3
commit ebbbb7332e
805 changed files with 838724 additions and 1905 deletions

View File

@@ -12,10 +12,11 @@ namespace BaseGames.Combat
public class HurtBox : MonoBehaviour
{
// ── 伤害接受方Awake 注入)──────────────────────────────────────────
private IDamageable _owner;
private IShieldable _shieldable; // 由 PlayerController.Awake() 注入
private ParrySystem _parrySystem; // Phase 2 由 PlayerController.Awake() 注入
private IPoiseSource _poiseSource; // Phase 2 由 EnemyBase.Awake() 注入
private IDamageable _owner;
private IShieldable _shieldable; // 由 PlayerController.Awake() 注入
private ParrySystem _parrySystem; // 由 PlayerController.Awake() 注入
private IPoiseSource _poiseSource; // 由 EnemyBase.Awake() 注入
private IStatusEffectable _statusEffectable; // Awake 缓存,避免每次受击调用 GetComponent
private bool _isHurtBoxInvincible;
private bool _isActive = true;
@@ -30,10 +31,18 @@ namespace BaseGames.Combat
public void SetPoiseSource(IPoiseSource src) => _poiseSource = src;
public void SetInvincible(bool value) => _isHurtBoxInvincible = value;
public void SetActive(bool value) => _isActive = value;
#if UNITY_EDITOR
// 付给编辑器的只读属性——避免反射并限制编辑器与运行时字段名耐合性。
public object EditorOwner => _owner;
public object EditorShieldable => _shieldable;
public object EditorParrySystem => _parrySystem;
public object EditorPoiseSource => _poiseSource;
public object EditorStatusEffectable => _statusEffectable;
#endif
private void Awake()
{
_owner = GetComponentInParent<IDamageable>();
_statusEffectable = GetComponentInParent<IStatusEffectable>();
if (_owner == null)
Debug.LogWarning($"[HurtBox] {name}: 父节点中未找到 IDamageable 实现。", this);
}
@@ -50,12 +59,12 @@ namespace BaseGames.Combat
if ((_owner.IsInvincible || _isHurtBoxInvincible)
&& !info.Flags.HasFlag(DamageFlags.IgnoreIFrame)) return;
// 2. 弹反检查(Phase 1 _parrySystem == null 跳过)
// 2. 弹反检查_parrySystem == null 跳过)
// ParrySystem 只暴露窗口状态,伤害数据留在 Combat 层,无跨程序集数据依赖。
if (_parrySystem != null && info.Flags.HasFlag(DamageFlags.CanBeParried))
if (_parrySystem.ConsumeParry()) return;
// 3. 霸体检查(Phase 1 _poiseSource == null 跳过)
// 3. 霸体检查_poiseSource == null 跳过)
if (!info.Flags.HasFlag(DamageFlags.ForceBreak) && _poiseSource != null)
{
PoiseLevel curPoise = _poiseSource.GetCurrentPoiseLevel();
@@ -96,11 +105,23 @@ namespace BaseGames.Combat
});
// 8. 状态效果触发DoT — Fire / Poison
// 使用接口避免对 StatusEffects 程序集的直接依赖
if (_owner is UnityEngine.MonoBehaviour mb)
{
mb.GetComponent<IStatusEffectable>()?.ApplyStatusEffect(info.Type);
}
// _statusEffectable 已在 Awake 中缓存,无需每次受击调用 GetComponent
_statusEffectable?.ApplyStatusEffect(info.Type);
}
#if UNITY_EDITOR
private void OnDrawGizmos()
{
var col = GetComponent<Collider2D>();
if (col == null) return;
// 激活时红色不透明,无敌/非激活时半透明
Gizmos.color = (_isActive && !_isHurtBoxInvincible)
? new UnityEngine.Color(1f, 0f, 0f, 0.45f)
: new UnityEngine.Color(1f, 0f, 0f, 0.1f);
Gizmos.DrawCube(col.bounds.center, col.bounds.size);
Gizmos.color = new UnityEngine.Color(1f, 0f, 0f, 0.9f);
Gizmos.DrawWireCube(col.bounds.center, col.bounds.size);
}
#endif
}
}